Jump to content

DB error: Syntax Error


duncan_cowan

Recommended Posts

Hi I ran this code to put info from a form into a file but for some reason it just says "DB Error: syntax error" when it is run.CODE:

<?phprequire("protected/db_connect.php");$random = rand(1000000000, 9000000000); // between 0 and 100 inclusive if (!$_POST['uname'] | !$_POST['passwd'] | !$_POST['passwd_again'] | !$_POST['email']) { die('You did not fill in a required field.'); } // check if username exists in database. if (!get_magic_quotes_gpc()) { $_POST['uname'] = addslashes($_POST['uname']); } $name_check = $db_object->query("SELECT username FROM unactivated_users WHERE username = '".$_POST['uname']."'"); if (DB::isError($name_check)) { die($name_check->getMessage()); } $name_checkk = $name_check->numRows(); if ($name_checkk != 0) { die('Sorry, the username: <strong>'.$_POST['uname'].'</strong> is already taken, please pick another one.'); } // check passwords match if ($_POST['passwd'] != $_POST['passwd_again']) { die('Passwords did not match.'); } // check e-mail format if (!preg_match("/.*@.*..*/", $_POST['email']) | preg_match("/(<|>)/", $_POST['email'])) { die('Invalid e-mail address.'); } // no HTML tags in username, website, location, password $_POST['uname'] = strip_tags($_POST['uname']); $_POST['passwd'] = strip_tags($_POST['passwd']); $_POST['website'] = strip_tags($_POST['website']); $_POST['location'] = strip_tags($_POST['location']); // check show_email data if ($_POST['show_email'] != 0 & $_POST['show_email'] != 1) { die('Nope'); } // now we can add them to the database. // encrypt password $_POST['passwd'] = md5($_POST['passwd']); if (!get_magic_quotes_gpc()) { $_POST['passwd'] = addslashes($_POST['passwd']); $_POST['email'] = addslashes($_POST['email']); $_POST['website'] = addslashes($_POST['website']); $_POST['location'] = addslashes($_POST['location']); } $regdate = date('m d, Y'); $insert = "INSERT INTO unactivated_users ( username, password, regdate, email, location, show_email, last_login, act_num, army species) VALUES ( '".$_POST['uname']."', '".$_POST['passwd']."', '$regdate', '".$_POST['email']."', '".$_POST['location']."', '".$_POST['show_email']."', 'Never', '$random', '".$_POST['species']."')"; $add_member = $db_object->query($insert); if (DB::isError($add_member)) { die($add_member->getMessage()); } require("regmail.php"); $db_object->disconnect(); header("http://www.wasper-rocker.co.uk/jstreg.php")?>
Why does it say this please??
Link to comment
Share on other sites

Hi I ran this code to put info from a form into a file but for some reason it just says "DB Error: syntax error" when it is run.Why does it say this please??
Whenever I get an error like this, it's usually because I'm missing something simple like quotes around a parameter or I've forgotten to place a comma in there. Try echo'ing out the SQL to your screen rather than running it on your DB to see if it is formatted correctly. Then, you might try manually running the SQL against your DB to see if the database generates a more helpfull error message than PHP does.
Link to comment
Share on other sites

Temporarily modify your code to debug it. Rather than:

...$add_member = $db_object->query($insert);if (DB::isError($add_member)) {die($add_member->getMessage());}

Try:

...echo $insert;//$add_member = $db_object->query($insert);//if (DB::isError($add_member)) {//die($add_member->getMessage());//}

This will display on the screen the SQL INSERT command that you are attempting to run against the database. Looking at that command as it would appear to the database may help you determine where the error is.

Link to comment
Share on other sites

Now it says:

INSERT INTO unactivated_users ( username, password, regdate, email, location, show_email, last_login, act_num, army species) VALUES ( 'duncan', 'b8f1fb7ac592b5a8fa371303e49343ef', '10 10, 2006', 'duncan.cowan@btinternet.com', 'Liverpool, England, UK', 'yes', 'Never', '457759336', 'wizards')
???
Link to comment
Share on other sites

thats exactly the point! Its to see what you are putting into the database.By manually running the query against your server, which I do constantly, he means going to like phpmyadmin on your server, and copy and pasting a specific query into it. You could also just put it in another file and run it. You then do this with every query on your page until you find the erronous one(s) and tweak them until they work! Its pretty simple. Just copy and paste until you find which one is giving the error.

Link to comment
Share on other sites

i have found out what was wrong with it and fixed it it was because there was a space inbetween army & species:

$insert = "INSERT INTO unactivated_users (username,password,regdate,email,location,show_email,last_login,act_num,army species)

For some reason this was stopping it from working even though the name of the row in the table had a space in aswell!!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...