05-30-2005, 09:13 PM
|
#4 (permalink)
|
|
The Acquainted
Join Date: Mar 2005
Posts: 177
Thanks: 0
|
This code is untested. If you don't understand what a part of it is doing just ask. It's fairly simple, but if you run into problems try looking up the php function first.
PHP Code:
// check for variables to contain data
if (!empty($_POST['title']))
{
// add values to array for later use
$row[] = 'title';
$value[] = "'" . addslashes($_POST['title']) . "'";
}
if (!empty($_POST['publisher']))
{
$row[] = 'publisher';
$value[] = "'" . addslashes($_POST['publisher']) . "'";
}
// check to see if we need to insert data
if (count($row) > 0)
{
// create query
// the implode functions will create values in the query and if both
// values are set will create a query looking like this:
// INSERT INTO xbox (title, publisher) VALUES ('Title Posted Value', 'Publisher Posted Value')
$sql = "INSERT INTO xbox (" . implode(',', $row) . ") VALUES (" . implode(',', $value) . ")";
if (@mysql_query($sql))
{
echo '<p>Your info has been added.</p>';
}
else
{
echo '<p>Error adding submitted info: ' . mysql_error(). '</p>';
}
}
else
{
// no data inserted
}
|
|
|
|