View Single Post
Old 05-30-2005, 09:13 PM   #4 (permalink)
CreativeLogic
The Acquainted
 
Join Date: Mar 2005
Posts: 177
Thanks: 0
CreativeLogic is on a distinguished road
Default

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

CreativeLogic is offline  
Reply With Quote