@ causing an issue in inserts

They have: 461 posts

Joined: Jul 2003

i thought having the '' around the variables would solve it... i also fixed the second one to have that. can anyone explain why it's happening? i can't find anything relevant when using google to search mysql.com for "@ in variables" i get back pages dealing with user creation for some reason

Quote: debug: insert to user: INSERT INTO users (username, password, email, last_login_ip, last_login_date, enroll, gender) VALUES ('Neo', '9cc9e1f6a22e05307d6831087ef5d1e6', '[email protected]', '192.168.1.100', '2003-08-27 19:11:09', '2003-08-27 19:11:09', 'M')
1064
You have an error in your SQL syntax near '@hotmail.com, 192.168.1.100, 2003-08-27 19:11:09, 2003-08-27 19:11:09, M)' at line 1

the code causing the issue:

<?php
function s2dbadd($db, $badaim, $badicq, $badmsn, $badyim){ # step 2 db additions
 
include(\"/home/joshua/includes/fyd.altincs.php\"); # includes file (precautionary measure)
  # step 2 non-passed variables
 
$un=clean($_POST['un']); $pw=MD5($_POST['pw']); $email=clean($_POST['email']);  $dobm=clean($_POST['month']); $dobd=clean($_POST['day']); $doby=clean($_POST['year']); $gender=clean($_POST['gender']); $sexpref=clean($_POST['sexpref']); $marstat=clean($_POST['marstat']); $country=clean($_POST['country']); $feet=clean($_POST['feet']); $inches=clean($_POST['inches']); $waist=clean($_POST['waist']); $eye=clean($_POST['eye']); $hair=clean($_POST['hair']); $weight=clean($_POST['weight']); $body=clean($_POST['body']); $education=clean($_POST['education']); $employment=clean($_POST['employment']); $religion=clean($_POST['religion']); $ethnicity=clean($_POST['ethnicity']); $city=clean($_POST['city']); $spt=clean($_POST['spt']); $selfcat=clean($_POST['selfcat']); $aim=clean($_POST['aim']); $icq=clean($_POST['icq']); $mirc=clean($_POST['mirc']); $msn=clean($_POST['msn']); $yim=clean($_POST['yim']); # || date of birth month/day/year, gender, sexual preference, marital status, country, height (feet/inches), waist, eye, hair, weight, body type, education level, employment status, religion, ethnicity, city, state/province/territory, selfcat || aim, icq, mirc, msn, yim
 
$llip=$_SERVER['REMOTE_ADDR']; $aff='Regular';# variables not in post but needed
 
$lld=gmdate(\"Y-m-d H:i:s\", time()); # get the GMT date/time based on time() (which returns the GMT timestamp)
 
$enroll=gmdate(\"Y-m-d H:i:s\", time()); # get the GMT date/time based on time() (which returns the GMT timestamp)
 
  # set various elements in prep to enter into the db
  if(isset(
$aim)&&$badaim){ $aim=NULL; } # set aim to a NULL entry if needed
  if(isset(
$icq)&&$badicq){ $icq=NULL; } # set icq to a NULL entry if needed
  if(isset(
$msn)&&$badmsn){ $msn=NULL; } # set msn to a NULL entry if needed
  if(isset(
$yim)&&$badyim){ $yim=NULL; } # set yim to a NULL entry if needed
 
$height=(12*$feet)+$inches; # set height for storage
 
$dob=$doby.'-'.$dobm.'-'.$dobd; # set DOB
 
  # make primary user table entry, retrieve uid
  mysql_query(\"INSERT INTO users (username, password, email, last_login_ip, last_login_date, enroll, gender) VALUES ('
$un', '$pw', '$email', '$llip', '$lld', '$enroll', '$gender')\", $db); # sets the main user table
 
$query=\"INSERT INTO users (username, password, email, last_login_ip, last_login_date, enroll, gender) VALUES ('$un', '$pw', '$email', '$llip', '$lld', '$enroll', '$gender')\";
 
$errno=mysql_errno($db); $err=mysql_error($db); echo \"<p>debug: insert to user: $query<br />$errno <br />$err</p>\";
 
$getuid=mysql_query(\"SELECT uid FROM users WHERE username='$un'\", $db); # query for uid
 
$uid=mysql_fetch_array($getuid); # set the uid
  # make stats table entry
  mysql_query(\"INSERT INTO stats (uid, username, dob, affiliation, sex_pref, mar_stat, country, height, waist, eye_color, hair_color, weight, body_type, education, employment, religion, ethnic, city, spt, self_cat, aim, icq, mirc, msn, yim) VALUES (
$uid, $username, $dob, $aff, $sexpref, $marstat, $country, $height, $waist, $eye, $hair, $weight, $body, $education, $employment, $religion, $ethnicity, $city, $spt, $selfcat, $aim, $icq, $mirc, $msn, $yim)\", $db); #insert stats into stats table
  # set uid into a cookie
 
$expire=time()+60*60; # set expiration an hour from now
  setcookie(uid, md5(
$uid), $expire);
}
?>

POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

I dont see how you could possibly come up with that debug text. Your "debug:" line shows one sql query, yet the mysql_error() text shows another.

I see nothing wrong with the sql in the "debug:" line.
But the sql in the mysql_error() text needs single quotes.

As a general rule, all non-numeric fields require quotes.

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 461 posts

Joined: Jul 2003

i didn't even notice that becasue wheni checked the code it has the '' around everything, including numbers

just noticed a different error as i went to double check it's saved like that. let's see if saving it again fixed it

POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.

They have: 461 posts

Joined: Jul 2003

well it's working fine now. interesting

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.