S A N T A Posted April 30, 2008 Share Posted April 30, 2008 k this register code wont work wahts up? <?php session_start(); require("config.php"); $db = mysql_connect($dbhost, $dbuser); mysql_select_db($dbdatabase, $db); if($_POST['submit']) { if($_POST['password'] == $_POST['password2']) { $checksql = "SELECT * FROM user WHERE username = '" . $_POST['username'] . "';"; $checkresult = mysql_query($checksql)or die(mysql_error()); $checknumrows = mysql_num_rows($checkresult); if($checknumrows == 1) { header("Location: " . $config_basedir . "reg.php?error=taken"); } else { for($i = 0; $i < 16; $i++) { $randomstring .= chr(mt_rand(32,126)); } $verifyurl = "http://localhost/verify.php"; $verifystring = urlencode($randomstring); $validusername = $_POST['username']; $sql = "INSERT INTO user(username, password, name, lastname) VALUES('" . $_POST['username'] . "', '" . $_POST['password'] . "' '" . $_POST['name'] . "' '" . $_POST['lastname'] . "' '" . addslashes($randomstring) . "', 0);"; mysql_query($sql)or die(mysql_error()); require("header.php"); } else { header("Location: " . $config_basedir . "reg.php?error=pass"); } else { require("header.php"); switch($_GET['error']) { case "pass": echo "Passwords do not match!"; break; case "taken": echo "Username taken, please use another."; break; case "no": echo "Incorect login details!"; break; } ?> <h2>Register</h2> To register on <?php echo $config_blogname; ?>, filll out the form below. <form action="<?php echo $SCRIPT_NAME ?>" method="POST"> <table> <tr> <td>Username</td> <td><input type="text" name="username"></td> </tr> <tr> <td>Password</td> <td><input type="password" name="password"></td> </tr> <tr> <td>Re-type Password</td> <td><input type="password" name="password2"></td> </tr> <tr> <td>First Name</td> <td><input type="text" name="name"></td> </tr> <tr> <td>Last Name</td> <td><input type="text" name="lastname"></td> </tr> <tr> <td></td> <td><input type="submit" value="Register!"></td> </tr> </table> </form> <?php } require("footer.php"); ?> thanks in advance Link to comment https://forums.phpfreaks.com/topic/103515-register-prob/ Share on other sites More sharing options...
Fadion Posted April 30, 2008 Share Posted April 30, 2008 Are u getting any errors? In which block is it stuck? We cant do blind debug... Link to comment https://forums.phpfreaks.com/topic/103515-register-prob/#findComment-530027 Share on other sites More sharing options...
priti Posted April 30, 2008 Share Posted April 30, 2008 you again got this <td><input type="submit" value="Register!"></td> in your code :-) Link to comment https://forums.phpfreaks.com/topic/103515-register-prob/#findComment-530046 Share on other sites More sharing options...
S A N T A Posted April 30, 2008 Author Share Posted April 30, 2008 sorry the error is: Parse error: syntax error, unexpected T_ELSE in C:\xampp\htdocs\reg.php on line 33 Link to comment https://forums.phpfreaks.com/topic/103515-register-prob/#findComment-530340 Share on other sites More sharing options...
revraz Posted April 30, 2008 Share Posted April 30, 2008 Means you probably have two ELSE's in the same IF statement. Change one to ELSEIF or redo your logic. Link to comment https://forums.phpfreaks.com/topic/103515-register-prob/#findComment-530358 Share on other sites More sharing options...
S A N T A Posted April 30, 2008 Author Share Posted April 30, 2008 ok so i changed one to "ELSEIF" and i get the same error Link to comment https://forums.phpfreaks.com/topic/103515-register-prob/#findComment-530362 Share on other sites More sharing options...
miracle_potential Posted April 30, 2008 Share Posted April 30, 2008 <?php session_start(); require("config.php"); $db = mysql_connect($dbhost, $dbuser); mysql_select_db($dbdatabase, $db); if($_POST['submit']) { if($_POST['password'] == $_POST['password2']) { $checksql = "SELECT * FROM user WHERE username = '" . $_POST['username'] . "';"; $checkresult = mysql_query($checksql)or die(mysql_error()); $checknumrows = mysql_num_rows($checkresult); if($checknumrows == 1) { header("Location: " . $config_basedir . "reg.php?error=taken"); } else { for($i = 0; $i < 16; $i++) { $randomstring .= chr(mt_rand(32,126)); } $verifyurl = "http://localhost/verify.php"; $verifystring = urlencode($randomstring); $validusername = $_POST['username']; $sql = "INSERT INTO user(username, password, name, lastname) VALUES('" . $_POST['username'] . "', '" . $_POST['password'] . "' '" . $_POST['name'] . "' '" . $_POST['lastname'] . "' '" . addslashes($randomstring) . "', 0);"; mysql_query($sql)or die(mysql_error()); require("header.php"); } else { header("Location: " . $config_basedir . "reg.php?error=pass"); } else { require("header.php"); switch($_GET['error']) { case "pass": echo "Passwords do not match!"; break; case "taken": echo "Username taken, please use another."; break; case "no": echo "Incorect login details!"; break; } ?> <h2>Register</h2> To register on <?php echo $config_blogname; ?>, filll out the form below. <form action="<?php echo $SCRIPT_NAME ?>" method="POST"> <table> <tr> <td>Username</td> <td><input type="text" name="username"></td> </tr> <tr> <td>Password</td> <td><input type="password" name="password"></td> </tr> <tr> <td>Re-type Password</td> <td><input type="password" name="password2"></td> </tr> <tr> <td>First Name</td> <td><input type="text" name="name"></td> </tr> <tr> <td>Last Name</td> <td><input type="text" name="lastname"></td> </tr> <tr> <td></td> <td><input type="submit" value="Register!"></td> </tr> </table> </form> <?php } require("footer.php"); ?> Replace this block else { for($i = 0; $i < 16; $i++) { $randomstring .= chr(mt_rand(32,126)); } $verifyurl = "http://localhost/verify.php"; $verifystring = urlencode($randomstring); $validusername = $_POST['username']; $sql = "INSERT INTO user(username, password, name, lastname) VALUES('" . $_POST['username'] . "', '" . $_POST['password'] . "' '" . $_POST['name'] . "' '" . $_POST['lastname'] . "' '" . addslashes($randomstring) . "', 0);"; mysql_query($sql)or die(mysql_error()); require("header.php"); } else { header("Location: " . $config_basedir . "reg.php?error=pass"); } else { require("header.php"); switch($_GET['error']) { case "pass": echo "Passwords do not match!"; break; case "taken": echo "Username taken, please use another."; break; case "no": echo "Incorect login details!"; break; } WITH else { for($i = 0; $i < 16; $i++) { $randomstring .= chr(mt_rand(32,126)); } $verifyurl = "http://localhost/verify.php"; $verifystring = urlencode($randomstring); $validusername = $_POST['username']; $sql = "INSERT INTO user(username, password, name, lastname) VALUES('" . $_POST['username'] . "', '" . $_POST['password'] . "' '" . $_POST['name'] . "' '" . $_POST['lastname'] . "' '" . addslashes($randomstring) . "', 0);"; $query = mysql_query($sql)or die(mysql_error()); require("header.php"); } elseif(!$query) { header("Location: " . $config_basedir . "reg.php?error=pass"); } elseif(!empty($_GET['error'])){ require("header.php"); switch($_GET['error']) { case "pass": echo "Passwords do not match!"; break; case "taken": echo "Username taken, please use another."; break; case "no": echo "Incorect login details!"; break; } Have a go with that fella, its really hard to debug this script its laid out a bit rough xD good luck though mate Link to comment https://forums.phpfreaks.com/topic/103515-register-prob/#findComment-530380 Share on other sites More sharing options...
S A N T A Posted April 30, 2008 Author Share Posted April 30, 2008 i get Parse error: syntax error, unexpected T_ELSEIF in C:\xampp\htdocs\reg.php on line 33 Link to comment https://forums.phpfreaks.com/topic/103515-register-prob/#findComment-530395 Share on other sites More sharing options...
miracle_potential Posted April 30, 2008 Share Posted April 30, 2008 Add }} under the last require/or before you never closed your first if statements to PHP that means you've never made an if and when there isnt an if there cant be an else Link to comment https://forums.phpfreaks.com/topic/103515-register-prob/#findComment-530405 Share on other sites More sharing options...
S A N T A Posted April 30, 2008 Author Share Posted April 30, 2008 ok so i tried changing the code to <?php session_start(); require("config.php"); $db = mysql_connect($dbhost, $dbuser); mysql_select_db($dbdatabase, $db); if($_POST['submit']) { if($_POST['password'] == $_POST['password2']) { $checksql = "SELECT * FROM user WHERE username = '" . $_POST['username'] . "';"; $checkresult = mysql_query($checksql)or die(mysql_error()); $checknumrows = mysql_num_rows($checkresult); if($checknumrows == 1) { header("Location: " . $config_basedir . "reg.php?error=taken"); } else { for($i = 0; $i < 16; $i++) { $randomstring .= chr(mt_rand(32,126)); } $verifyurl = "http://localhost/verify.php"; $verifystring = urlencode($randomstring); $validusername = $_POST['username']; $sql = "INSERT INTO user(username, password, name, lastname) VALUES('" . $_POST['username'] . "', '" . $_POST['password'] . "' '" . $_POST['name'] . "' '" . $_POST['lastname'] . "' '" . addslashes($randomstring) . "', 0);"; $query = mysql_query($sql)or die(mysql_error()); require("header.php"); } } if(!$query) { header("Location: " . $config_basedir . "reg.php?error=pass"); if(!empty($_GET['error'])){ require("header.php"); switch($_GET['error']) { case "pass": echo "Passwords do not match!"; break; case "taken": echo "Username taken, please use another."; break; case "no": echo "Incorect login details!"; break; } and i got Parse error: syntax error, unexpected $end in C:\xampp\htdocs\reg.php on line 54 Link to comment https://forums.phpfreaks.com/topic/103515-register-prob/#findComment-530716 Share on other sites More sharing options...
roopurt18 Posted April 30, 2008 Share Posted April 30, 2008 Have you made any real effort to figure out why this isn't working yourself? Or are you just looking for copy and paste solutions? Whenever you have a syntax error, you can always, always figure out where the error is by commenting out chunks of code at a time. This is where a good editor's automatic commenting (usually ctrl + /) comes in handy. Start around where the error is reported. Start at the most nested piece of code and comment it out. If you get the error move up on level on your indentation and comment that section. Repeat until the error goes away. It's repetitive but you can find the error that way. Also, syntax errors will always come up in coding so you might as well learn how to fix them yourself now. Link to comment https://forums.phpfreaks.com/topic/103515-register-prob/#findComment-530732 Share on other sites More sharing options...
S A N T A Posted April 30, 2008 Author Share Posted April 30, 2008 ok so i fixed the error: <?php session_start(); require("config.php"); $db = mysql_connect($dbhost, $dbuser); mysql_select_db($dbdatabase, $db); if($_POST['submit']) { if($_POST['password'] == $_POST['password2']) { $checksql = "SELECT * FROM user WHERE username = '" . $_POST['username'] . "';"; $checkresult = mysql_query($checksql)or die(mysql_error()); $checknumrows = mysql_num_rows($checkresult); if($checknumrows == 1) { header("Location: " . $config_basedir . "reg.php?error=taken"); } else { for($i = 0; $i < 16; $i++) { $randomstring .= chr(mt_rand(32,126)); } $verifyurl = "http://localhost/verify.php"; $verifystring = urlencode($randomstring); $validusername = $_POST['username']; $sql = "INSERT INTO user(username, password, name, lastname) VALUES('" . $_POST['username'] . "', '" . $_POST['password'] . "' '" . $_POST['name'] . "' '" . $_POST['lastname'] . "' '" . addslashes($randomstring) . "', 0);"; $query = mysql_query($sql)or die(mysql_error()); require("header.php"); } if(!$query) { header("Location: " . $config_basedir . "reg.php?error=pass"); } if(!empty($_GET['error'])){ require("header.php"); switch($_GET['error']) { case "pass": echo "Passwords do not match!"; break; case "taken": echo "Username taken, please use another."; break; case "no": echo "Incorect login details!"; break; } ?> <h2>Register</h2> To register on <?php echo $config_blogname; ?>, filll out the form below. <form action="<?php echo $SCRIPT_NAME ?>" method="POST"> <table> <tr> <td>Username</td> <td><input type="text" name="username"></td> </tr> <tr> <td>Password</td> <td><input type="password" name="password"></td> </tr> <tr> <td>Re-type Password</td> <td><input type="password" name="password2"></td> </tr> <tr> <td>First Name</td> <td><input type="text" name="name"></td> </tr> <tr> <td>Last Name</td> <td><input type="text" name="lastname"></td> </tr> <tr> <td></td> <td><input type="submit" value="Register!"></td> </tr> </table> </form> <?php } } } require("footer.php"); ?> but now the form doesn't display Link to comment https://forums.phpfreaks.com/topic/103515-register-prob/#findComment-530741 Share on other sites More sharing options...
miracle_potential Posted May 1, 2008 Share Posted May 1, 2008 I did notice you had header.php called twice, but to be honest roopurt is right you need to add comments and echos as you go to debug this yourself your programs only as good as your debugging. Link to comment https://forums.phpfreaks.com/topic/103515-register-prob/#findComment-530910 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.