Oedwards Posted December 9, 2009 Share Posted December 9, 2009 I am trying to get this script to run but i get the error Parse error: syntax error, unexpected $end in /home/pdgeman/public_html/Register.php on line 18 I have tried all sorts of stuff.. please help me! Here is the code: <? $DBhost = "localhost"; $DBuser = ""; $DBpass = ""; $DBName = ""; $table = ""; $uname = $_POST['uname']; $pass = $_POST['pass']; mysql_connect($DBhost,$DBuser,$DBpass); @mysql_select_db("$DBName"); $query = mysql_num_rows(mysql_query("SELECT * FROM usernames WHERE username='$uname'")); if(username == '$uname'); { die(); $result = mysql_query($query); ?> Link to comment https://forums.phpfreaks.com/topic/184504-help-with-code/ Share on other sites More sharing options...
rajivgonsalves Posted December 9, 2009 Share Posted December 9, 2009 You missed out a closing brackets, this if(username == '$uname'); { die(); $result = mysql_query($query); should be if(username == '$uname'); { die(); $result = mysql_query($query); } Link to comment https://forums.phpfreaks.com/topic/184504-help-with-code/#findComment-973978 Share on other sites More sharing options...
Oedwards Posted December 9, 2009 Author Share Posted December 9, 2009 Oh.... lol. I am very new at this type of coding, I usually just copy and paste. I am going to try it now. Link to comment https://forums.phpfreaks.com/topic/184504-help-with-code/#findComment-973979 Share on other sites More sharing options...
Oedwards Posted December 9, 2009 Author Share Posted December 9, 2009 <? $DBhost = "localhost"; $DBuser = ""; $DBpass = ""; $DBName = ""; $table = ""; $uname = $_POST['uname']; $pass = $_POST['pass']; mysql_connect($DBhost,$DBuser,$DBpass); @mysql_select_db("$DBName"); $query = mysql_num_rows(mysql_query("SELECT * FROM usernames WHERE username='$uname'")); if(username == '$uname') die(); else $SQL = "INSERT INTO $table (Username, Password) VALUES ('$uname' , '$pass')"; $result = mysql_query($query); ?> this is my current code, it doesn't display an error but it doesn't add anything to the database either... I am so lost. Someone told me this code wouldn't work but didn't explain why.. does anybody know? Link to comment https://forums.phpfreaks.com/topic/184504-help-with-code/#findComment-974003 Share on other sites More sharing options...
rajivgonsalves Posted December 9, 2009 Share Posted December 9, 2009 I would just like to say logical errors right code would be <?php $DBhost = "localhost"; $DBuser = ""; $DBpass = ""; $DBName = ""; $table = ""; mysql_connect($DBhost,$DBuser,$DBpass) or die('Cannot connect to database'); mysql_select_db($DBName) or die('Cannot select database'); $uname = isset($_POST['uname']) ? mysql_real_escape_string($_POST['uname']) : ''; $pass = isset($_POST['pass']) ? mysql_real_escape_string($_POST['pass']) : ''; $result = mysql_query("SELECT * FROM usernames WHERE username='$uname'") or die('Cannot Execute Query:'.mysql_error()); $rows = mysql_num_rows($result); if($rows > 0) { die('Username already exists'); } else { $query = "INSERT INTO $table (Username, Password) VALUES ('$uname' , '$pass')"; $result = mysql_query($query); } ?> Link to comment https://forums.phpfreaks.com/topic/184504-help-with-code/#findComment-974008 Share on other sites More sharing options...
Oedwards Posted December 9, 2009 Author Share Posted December 9, 2009 dude, you are awesome, doesn't explain to me why it wouldn't work, but none the less, at least it works now.. Link to comment https://forums.phpfreaks.com/topic/184504-help-with-code/#findComment-974009 Share on other sites More sharing options...
rajivgonsalves Posted December 9, 2009 Share Posted December 9, 2009 actually if you compare the two codes you will know where you went wrong Link to comment https://forums.phpfreaks.com/topic/184504-help-with-code/#findComment-974016 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.