Jump to content

Registration script


Sooth

Recommended Posts

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.

Link to comment
Share on other sites

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>";
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.