ohdang888 Posted January 14, 2008 Share Posted January 14, 2008 i'm making a form where people can sign-up to be a member. their info autmatically goes into a database. i am now getting this error: Parse error: syntax error, unexpected '"', expecting ']' in C:\xampp\htdocs\sign_up.php on line 19 that's the first problem, but i had a problem earlier where it was connecting to the table, but it wasn;t inserting the info, it was creating blank lines, so i messed with it a bit and now i have that problem... Any ideas? Thanks! this is my code: <?php mysql_connect("localhost", "----", "----") or die(mysql_error()); mysql_select_db("members") or die(mysql_error()); if($_POST['submit']){ $_POST['username'] = trim($_POST['username']); if($_POST['username'] && strlen($_POST['username']) >= 3){ $query = mysql_query("SELECT `id` FROM `user` WHERE `username`='".$_POST['username']."' LIMIT 1"); if(mysql_num_rows($query)){ $error['userexists'] = 'Username exists'; } } else { $error['usernameinput'] = 'Please enter a username'; } $_POST['username'] = trim($_POST['username']); if($_POST['email'] && strlen($_POST['email]) >= 5){ $query = mysql_query("SELECT `id` FROM `user` WHERE `email`='".$_POST['email']."' LIMIT 1");//////////////[b]LINE 19[/b] if(mysql_num_rows($query)){ $error['emailexists'] = 'Email is already signed up!'; } } else { $error['emailinput'] = 'Please enter a valid e-mail'; } $_POST['email'] = trim($_POST['email']); if($_POST['email']){ if(!eregi("^[a-zA-Z0-9]+[a-zA-Z0-9_.-]*@[a-zA-Z0-9]+[a-zA-Z0-9_.-])*\.[a-z]{2,4}$", $_POST['email'])){ $error['emailerror'] = 'Email Incorrect'; } } else { $error['emailinput'] = 'Please supply an email address'; } if($_POST['password1'] && $_POST['password2']){ if($_POST['password1'] != $_POST['password2']){ $error['passmismatch'] = 'Passwords don\'t match'; } } else { $error['passwordinput'] = 'Please enter your password in both fields'; } } if(!$error && $_POST['submit']){ } else { $username = $_POST["username"]; $email = $_POST["email"]; $password = $_POST["password1"]; $sql="INSERT INTO `user` (`username`, `password`, `email`) VALUES ( '$username', '$password', '$email')"; mysql_query($sql) or die ( mysql_error()); } ?> <html> <form name=”reg” method=”post” > username: <input type=”text” name=”username” /><br /><?php echo $error[’userexists’]; echo $error[’usernameinput’]; ?> email: <input type=”text” name=”email” /><br /> password1: <input type=”password” name=”password1” /><br/> password2: <input type=”password” name=”password2” /><br/> <input type=submit name=”submit” value=”submit” /><br> </form> Quote Link to comment https://forums.phpfreaks.com/topic/86028-solved-form-help/ Share on other sites More sharing options...
rizla_za Posted January 14, 2008 Share Posted January 14, 2008 First Problem is on line 19 you have a " or ' the code is not liking. instead of: `username`='".$_POST['username']."' Try using: `username`='$_POST[username]' instead. As for your blank entries, it should only be a typo in one of your vairables, echo your vairables and c if they actually have a value Quote Link to comment https://forums.phpfreaks.com/topic/86028-solved-form-help/#findComment-439316 Share on other sites More sharing options...
KrisNz Posted January 14, 2008 Share Posted January 14, 2008 if($_POST['email'] && strlen($_POST['email]) >= 5){ You're missing a closing quote there, also further down you have... $error['passmismatch'] = 'Passwords don't match'; That should either be $error['passmismatch'] = 'Passwords don\'t match'; #or $error['passmismatch'] = "Passwords don't match"; Quote Link to comment https://forums.phpfreaks.com/topic/86028-solved-form-help/#findComment-439318 Share on other sites More sharing options...
rizla_za Posted January 14, 2008 Share Posted January 14, 2008 if($_POST['email'] && strlen($_POST['email]) >= 5){ You're missing a closing quote there, also further down you have... $error['passmismatch'] = 'Passwords don't match'; That should either be $error['passmismatch'] = 'Passwords don\'t match'; #or $error['passmismatch'] = "Passwords don't match"; Yup, well spotted I always miss those 1s 2 if($_POST['email'] && strlen($_POST['email]) >= 5){ should be.. if($_POST['email'] && strlen($_POST['email']) >= 5){ Quote Link to comment https://forums.phpfreaks.com/topic/86028-solved-form-help/#findComment-439322 Share on other sites More sharing options...
psychowolvesbane Posted January 14, 2008 Share Posted January 14, 2008 Try changing: $query = mysql_query("SELECT `id` FROM `user` WHERE `username`='".$_POST['username']."' LIMIT 1"); to: $query = mysql_query("SELECT id FROM user WHERE username ='$_POST['username']' LIMIT 1"); and the other one: $query = mysql_query("SELECT `id` FROM `user` WHERE `email`='".$_POST['email']."' LIMIT 1"); to $query = mysql_query("SELECT id FROM user WHERE email='$_POST['email']' LIMIT 1"); Quote Link to comment https://forums.phpfreaks.com/topic/86028-solved-form-help/#findComment-439323 Share on other sites More sharing options...
ohdang888 Posted January 14, 2008 Author Share Posted January 14, 2008 so how exactly will echo work... i know all about echo and all that.... but when i click "submit" and the page refreshes, its not showing up anything $username = $_POST["username"]; $email = $_POST["email"]; $password = $_POST["password1"]; echo $username; echo $email; echo $password; Quote Link to comment https://forums.phpfreaks.com/topic/86028-solved-form-help/#findComment-439324 Share on other sites More sharing options...
revraz Posted January 14, 2008 Share Posted January 14, 2008 That will just break his queries Try changing: $query = mysql_query("SELECT `id` FROM `user` WHERE `username`='".$_POST['username']."' LIMIT 1"); to: $query = mysql_query("SELECT id FROM user WHERE username ='$_POST['username']' LIMIT 1"); and the other one: $query = mysql_query("SELECT `id` FROM `user` WHERE `email`='".$_POST['email']."' LIMIT 1"); to $query = mysql_query("SELECT id FROM user WHERE email='$_POST['email']' LIMIT 1"); Quote Link to comment https://forums.phpfreaks.com/topic/86028-solved-form-help/#findComment-439325 Share on other sites More sharing options...
psychowolvesbane Posted January 14, 2008 Share Posted January 14, 2008 so how exactly will echo work... i know all about echo and all that.... but when i click "submit" and the page refreshes, its not showing up anything $username = $_POST["username"]; $email = $_POST["email"]; $password = $_POST["password1"]; echo $username; echo $email; echo $password; Change to $_POST['username']; and the same with the other ones, ' ' quotes needs to be used with Form values. Quote Link to comment https://forums.phpfreaks.com/topic/86028-solved-form-help/#findComment-439328 Share on other sites More sharing options...
ohdang888 Posted January 14, 2008 Author Share Posted January 14, 2008 now its not even creating blank rows.... its doing nothing,..... AHHHH if(!$error && $_POST['submit']){ ////// AM I SUPPOSED TO HAVE THE BELOW CODE RIGHT HERE???? } else { $username = $_POST['username']; $email = $_POST['email']; $password = $_POST['password1']; echo $username; echo $email; echo $password; echo '<br>'; echo 'HEY HEY HEY'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; $sql="INSERT INTO `user` (`username`, `password`, `email`) VALUES ( '$username', '$password', '$email')"; mysql_query($sql) or die ( mysql_error()); } } the hey hey hey isn;'t hsowing up after i click submit Quote Link to comment https://forums.phpfreaks.com/topic/86028-solved-form-help/#findComment-439332 Share on other sites More sharing options...
psychowolvesbane Posted January 14, 2008 Share Posted January 14, 2008 now its not even creating blank rows.... its doing nothing,..... AHHHH if(!$error && $_POST['submit']){ ////// AM I SUPPOSED TO HAVE THE BELOW CODE RIGHT HERE???? } else { $username = $_POST['username']; $email = $_POST['email']; $password = $_POST['password1']; echo $username; echo $email; echo $password; echo '<br>'; echo 'HEY HEY HEY'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; $sql="INSERT INTO `user` (`username`, `password`, `email`) VALUES ( '$username', '$password', '$email')"; mysql_query($sql) or die ( mysql_error()); } } the hey hey hey isn;'t hsowing up after i click submit Echo using "" and anything that need quotes inside of an echo use ' ' quotes; P.S. don't need to quote at all if it is just a variable. Quote Link to comment https://forums.phpfreaks.com/topic/86028-solved-form-help/#findComment-439334 Share on other sites More sharing options...
KrisNz Posted January 14, 2008 Share Posted January 14, 2008 I've done a bit of cleanup for you due to boredom, its not perfect (or tested) but I hope it will be helpful. <?php mysql_connect("localhost", "", "") or die(mysql_error()); mysql_select_db("members") or die(mysql_error()); $aError = array(); function basic_xss_clean($s) { $s = trim(strip_tags(mysql_real_escape_string($s))); return $s; } if (isset($_POST['submit'])) { $bHasErrors = false; $_POST['username'] = trim($_POST['username']); if ($_POST['username'] && strlen($_POST['username']) >= 3) { $query = mysql_query("SELECT id FROM user WHERE username='".$_POST['username']."' LIMIT 1"); if(mysql_num_rows($query)){ $aError['userexists'] = 'Username exists'; } } else { $aError['usernameinput'] = 'Please enter a username'; $bHasErrors = true; } $_POST['username'] = trim($_POST['username']); if ($_POST['email'] && strlen($_POST['email']) >= 5) { $query = mysql_query("SELECT id FROM user WHERE email='".$_POST['email']."' LIMIT 1");//////////////[b]LINE 19[/b] if (mysql_num_rows($query)){ $aError['emailexists'] = 'Email is already signed up!'; } } else { $aError['emailinput'] = 'Please enter a valid e-mail'; $bHasErrors = true; } $_POST['email'] = trim($_POST['email']); if ($_POST['email']) { if(!eregi("^[a-zA-Z0-9]+[a-zA-Z0-9_.-]*@[a-zA-Z0-9]+[a-zA-Z0-9_.-])*\.[a-z]{2,4}$", $_POST['email'])){ $aError['emailerror'] = 'Email Incorrect'; } } else { $aError['emailinput'] = 'Please supply an email address'; $bHasErrors = true; } if ($_POST['password1'] && $_POST['password2']) { if ($_POST['password1'] != $_POST['password2']) { $aError['passmismatch'] = "Passwords don't match"; } } else { $aError['passwordinput'] = 'Please enter your password in both fields'; $bHasErrors = true; } if ($bHasErrors == true) { //dump errors on screen in untidy fashion print_r($aError); } else { //consider moving these variable assignments along with some trim()'ing and strip_tags()'ing to the top and testing //those variables, it'll make things easier to work with $username = basic_xss_clean($_POST["username"]); $email = basic_xss_clean($_POST["email"]); $password = basic_xss_clean($_POST["password1"]); $sql="INSERT INTO user (username, password, email) VALUES ( '$username', '$password', '$email')"; //echo $sql; mysql_query($sql) or die ( mysql_error()); } } ?> <html> <form name="reg" method="post" > username: <input type="text" name="username" /><span><?php if (isset($aError['userexists'])) echo $aError['userexists']; if (isset($aError['usernameinput'])) echo $aError['usernameinput']; ?></span><br /> email: <input type="text" name="email" /><br /> password1: <input type="password" name="password1" /><br/> password2: <input type="password" name="password2" /><br/> <input type=submit name="submit" value="submit" /><br> </form> Quote Link to comment https://forums.phpfreaks.com/topic/86028-solved-form-help/#findComment-439345 Share on other sites More sharing options...
ohdang888 Posted January 15, 2008 Author Share Posted January 15, 2008 krisnz... i love you. omg. Thank you. It works now! Quote Link to comment https://forums.phpfreaks.com/topic/86028-solved-form-help/#findComment-439383 Share on other sites More sharing options...
Pancake Posted January 15, 2008 Share Posted January 15, 2008 is it just me, or is there nothing wrong with directly using a $_POST variable into an SQL query? Quote Link to comment https://forums.phpfreaks.com/topic/86028-solved-form-help/#findComment-439386 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.