Sooth Posted August 24, 2007 Share Posted August 24, 2007 Hi. I'm trying to make a registration script but it doesnt work. <?php $show_error1='0'; $show_error2='0'; $show_error3='0'; if($_POST['reg_username']==''||$_POST['reg_password1']==''||$_POST['reg_password2']==''||$_POST['reg_email']=='')$show_error1='1'; if($_POST['reg_password1']!=$_POST['reg_password2'])$show_error2='1'; mysql_connect($host,$user,$pass); @mysql_select_db($db)or die("<h2>Error</h2><p>Unable to select database.</p>"); $query="SELECT * FROM users WHERE nick='$_POST[reg_username]'"; mysql_close(); $result=mysql_query($query); $num=mysql_num_rows($result); if($num>0) { $show_error3='1'; } if($show_error1=='0'&&$show_error2=='0'&&$show_error3=='0') { mysql_connect($host,$user,$pass); @mysql_select_db($db)or die("<h2>Error</h2><p>Unable to select database.</p>"); $query="INSERT INTO users VALUES ('','$_POST[reg_username]','$_POST[reg_password1]','$_POST[reg_email]','','','','','','$_POST[reg_nationality]','$_POST[reg_sex]','','','','','','0')"; mysql_query($query); mysql_close(); ?> <h2>Register</h2> <p>Registration succesful! You may now login.</p> <?php } else { ?> <h2>Error</h2> <?php } if($show_error1=='1')echo "<p>You must complete all fields.</p>"; if($show_error2=='1')echo "<p>The password fields must match.</p>"; if($show_error3=='1')echo "<p>The username is already in the database.</p>"; ?> Whats the easiest way to check if the user is already in the database? I cant make an working script to do this. Quote Link to comment https://forums.phpfreaks.com/topic/66481-registration-script/ Share on other sites More sharing options...
xyn Posted August 24, 2007 Share Posted August 24, 2007 try this <?php $show_error1='0'; $show_error2='0'; $show_error3='0'; if($_POST['reg_username']==''||$_POST['reg_password1']==''||$_POST['reg_password2']==''||$_POST['reg_email']=='')$show_error1='1'; if($_POST['reg_password1']!=$_POST['reg_password2'])$show_error2='1'; mysql_connect($host,$user,$pass); @mysql_select_db($db)or die("<h2>Error</h2><p>Unable to select database.</p>"); $result=mysql_query("SELECT * FROM users WHERE nick='".$_POST[reg_username]."'"); $num=mysql_num_rows($result); if($num>0) { $show_error3='1'; } if( (!$show_error1) && (!$show_error2) && ($show_error3) ) { $query_reg="INSERT INTO users VALUES ('','$_POST[reg_username]','$_POST[reg_password1]','$_POST[reg_email]','','','','','','$_POST[reg_nationality]','$_POST[reg_sex]','','','','','','0')"; mysql_query($query_reg); ?> <h2>Register</h2> <p>Registration succesful! You may now login.</p> <?php } else { ?> <h2>Error</h2> <?php } if($show_error1=='1')echo "<p>You must complete all fields.</p>"; if($show_error2=='1')echo "<p>The password fields must match.</p>"; if($show_error3=='1')echo "<p>The username is already in the database.</p>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/66481-registration-script/#findComment-332864 Share on other sites More sharing options...
Sooth Posted August 24, 2007 Author Share Posted August 24, 2007 Its not working. The page is white. Quote Link to comment https://forums.phpfreaks.com/topic/66481-registration-script/#findComment-332876 Share on other sites More sharing options...
xyn Posted August 24, 2007 Share Posted August 24, 2007 did you change the vars to the correct ones? Quote Link to comment https://forums.phpfreaks.com/topic/66481-registration-script/#findComment-332886 Share on other sites More sharing options...
Sooth Posted August 24, 2007 Author Share Posted August 24, 2007 What vars? Quote Link to comment https://forums.phpfreaks.com/topic/66481-registration-script/#findComment-332890 Share on other sites More sharing options...
xyn Posted August 24, 2007 Share Posted August 24, 2007 hm i'll create you a new script. give me 5 mins Quote Link to comment https://forums.phpfreaks.com/topic/66481-registration-script/#findComment-332893 Share on other sites More sharing options...
Sooth Posted August 24, 2007 Author Share Posted August 24, 2007 OK Quote Link to comment https://forums.phpfreaks.com/topic/66481-registration-script/#findComment-332904 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.