...

View Full Version : Help debugging error



adammc
03-06-2007, 05:47 AM
Hi Guys,

I can't for the life of me work out why I keep getting this error:

ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE username='billybob')' at line 76




$query = "INSERT INTO matrimonial (
username,
phone,
mobile,
createdby,
maritalstatus,
havechildren,
starsign,
height,
bodytype,
complexion,
specialcases,
bloodgroup,
religion,
tongue,
caste,
subcaste,
gotra,
manglik,
familyvalues,
educationlevel,
educationarea,
occupation,
annualincome,
diet,
smoke,
drink,
convenienttime,
contact_details_dislay_status,
family_father,
family_mother,
family_brother,
family_sister,
personality,
background,
date_reg,
profile_complete) VALUES (

'$_SESSION[username]',
'$phone',
'$mobile',
'$createdby',
'$maritalstatus',
'$havechildren',
'$starsign',
'$height',
'$bodytype',
'$complexion',
'$specialcases',
'$bloodgroup',
'$religion',
'$tongue',
'$caste',
'$subcaste',
'$gotra',
'$manglik',
'$familyvalues',
'$educationlevel',
'$educationarea',
'$occupation',
'$annualincome',
'$diet',
'$smoke',
'$drink',
'$convenienttime',
'$contact_details_dislay_status',
'$family_father',
'$family_mother',
'$family_brother',
'$family_sister',
'$personality',
'$background',
'$currentdatetime',
'1'

WHERE username='$_SESSION[username]')";


# execute SQL statement
$result = @mysql_query ($query);

# check for error
if (!$result) { echo("ERROR: " . mysql_error() . "\n$query\n");

// Show errors, if any
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);

}



Can anyone possibly help?

chump2877
03-06-2007, 06:05 AM
'$background',
'$currentdatetime',
'1'

WHERE username='$_SESSION[username]')";

should be


'$background',
'$currentdatetime',
'1')

WHERE username='$_SESSION[username]'";

adammc
03-06-2007, 06:14 AM
Hi chump thanks for the reply :)

I just worked out that I stupidly put in a WHERE clause on an INSERT statement!

It just proves that cutting and pasting code to save time doesnt always work out like that ;)

aedrin
03-06-2007, 04:05 PM
'$_SESSION[username]', [PHP]

That should probably be escaped and quoted like this:

[PHP]
$query = " ... '{$_SESSION['username']}', ... ";


I'm surprised that it worked the way you have it.

I'm still hoping for the day that PHP treats unquoted indexes (that are not defined) as syntax errors.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum