Unholy Prayer Posted March 28, 2007 Share Posted March 28, 2007 My registration script won't work because of an issue with my mysql_query syntax but I can't figure out what the problem is. When I click the register button, it displays a message that says 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 ''Test2' at line 1 This is my code: <?php //Connect to the database... this is definitely an essential. require_once('config.php'); include('constants.php'); //Get the server date... $date = date("F j, Y"); //Include the header body/functions include('templates/default/header_body.tpl'); $action = $_GET["action"]; if($action == ""){ //What is this user's member number? $members = mysql_query("SELECT * FROM vbb_members"); $number = mysql_num_rows($members); $mem_no = $number + 1; $errors = "0"; //If the register button was not click clicked... if(empty($_POST['register'])) { echo "</tr><tr>"; //Display the form include('templates/default/register_body.tpl'); } //If it was clicked... if(isset($_POST['register'])) { //Transform inputs into strings for mysql insertion... $user = $_POST['username']; $password = md5($_POST['password']); $password_conf = md5($_POST['password_conf']); $email = $_POST['email']; $reg_date = $_POST['reg_date']; $mem_no = $_POST['mem_no']; $perm = $_POST['perm']; //Is the user name in use? $membername = "SELECT * FROM vbb_members WHERE username='$user"; $name_result = mysql_query($membername) or die("Error: ".mysql_error()); $name = mysql_num_rows($name_result); //Is the user's email already in use? $emails = "SELECT * FROM vbb_members WHERE email='$email''"; $getemails = mysql_query($emails) or die("Error: ".mysql_error()); $num_emails = mysql_num_rows($getemails); if($num_emails == 1){ echo "</tr><tr><td align='center' class='inputrow'>There is already an account registered with that email address. Please go back and choose another.</td></tr><tr>"; } //If it is in use... if($name == 1){ echo "</tr><tr><td align='center' class='inputrow'>The username you entered is already in use. Please go back and choose another.</td></tr><tr>"; $errors = $errors + 1; } //Check if any fields are blank and display error messages if they are. if(empty($_POST['username'])){ echo "<td align='center' class='inputrow'>You left the username field blank. Please go back and choose one.</td></tr><tr>"; $errors = $errors + 1; } if(empty($_POST['password'])){ echo "<td align='center' class='inputrow'>You left the password field blank. Please go back and choose a password.</td></tr><tr>"; $errors = $errors + 1; } if(empty($_POST['password_conf'])){ echo "<td align='center' class='inputrow'>You did not confirm your password. Please make sure your password is correct by filling in the confirm password field.</td></tr><tr>"; $errors = $errors + 1; } if(empty($_POST['email'])){ echo "<td align='center' class='inputrow'>You did not enter an email address. Please go back and tell us your email address.</td></tr><tr>"; $errors = $errors + 1; } //Did the passwords match? if($password != $password_conf){ //If they didn't match, display an error message. echo "<td align='center' class='inputrow'>Your passwords did not match. Please go back and re-enter your passwords so they match.</td></tr><tr>"; $errors = $errors + 1; } if($errors == 0) { mysql_query("INSERT INTO `vbb_members` (`username`,`password`,`email`,`reg_date`,`mem_no`,`perm`) values (`$user`, `$password`, `$email`, `$reg_date`, `$mem_no`, `$perm`)") or die("Error: ".mysql_error()); //Display a welcome to the forums message. echo "<td align='center' class='light1'>Welcome to the forums, $user! You can now <a href='login.php'>login</a> with the information you just provided.</td>"; } if($errors > 0) { echo "There were $errors errors with the data you provided."; } } } //And we're done! For now, at least. ?> Thanks in advance for the help. Quote Link to comment Share on other sites More sharing options...
papaface Posted March 28, 2007 Share Posted March 28, 2007 this: values (`$user`, `$password`, `$email`, `$reg_date`, `$mem_no`, `$perm`)") should be: values ('{$user}', '{$password}', '{$email}', '{$reg_date}', '{$mem_no}', '{$perm}')") Quote Link to comment Share on other sites More sharing options...
Unholy Prayer Posted March 28, 2007 Author Share Posted March 28, 2007 I changed it, but it's still the same error. Quote Link to comment Share on other sites More sharing options...
papaface Posted March 28, 2007 Share Posted March 28, 2007 its this: $membername = "SELECT * FROM vbb_members WHERE username='$user"; should be: $membername = "SELECT * FROM vbb_members WHERE username='{$user}'"; Quote Link to comment Share on other sites More sharing options...
Unholy Prayer Posted March 28, 2007 Author Share Posted March 28, 2007 Thank you. I have been trying to figure that out forever. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.