View Single Post
Old 03-06-2013, 02:06 AM   PM User | #8
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,172
Thanks: 59
Thanked 3,995 Times in 3,964 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Missing the apostrophes around the PHP variables. Why did you think you could omit them in the UPDATE section if you needed them in the INSERT section???

But I'd do this:
Code:
// ensure no sql injection and also put the apostrophes around each value
// so that you only have to do this once!
function clean( $val )
{
    return "'" . mysql_real_escape_string( $val ) . "'"
}
// do it for each value:
$gamename = clean($gamename);
$cleangc = clean($cleangc);
$region = clean($region);
$mode = clean($mode);
$vmc = clean($vmc);
$smb = clean($smb);
$hdd = clean($hdd);
$usb = clean($usb);
$notes = clean($notes);
$comp = clean($comp);

$sql = "INSERT INTO $tbl_name(gamename, gamecode, region, mode, vmc, smb, hdd, usb, notes, comp)
       VALUES($gamename,$cleangc,$region,$mode,$vmc,$smb,$hdd,$usb,$notes,$comp) "
     ON DUPLICATE KEY UPDATE 
     gamename = IF(gamename = '', $gamename, gamename),
     region = IF (gamename = '', $region, region),
     mode = IF(gamename = '', $mode, mode),
     vmc = IF(gamename = '', $vmc, vmc), 
     smb = IF(gamename = '', $smb, smb), 
     hdd = IF(gamename = '', $hdd, hdd), 
     usb = IF(gamename = '', $usb, usb), 
     notes = IF(gamename = '', $notes, notes), 
     comp = IF(gamename = '', $comp, comp)";
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
bemore (03-06-2013)