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.