Jump to content

Help with signup script


eFlame

Recommended Posts

Im quite new to php and am trying to make a signup script, so far my script contains the registration form, and the registration info, but when i try to use it i get a error, and i don't know what to do.

 

reg_info.php

<?

include("config.php");

$check[0] = mysql_query("SELECT email FROM Account WHERE email = '$email'");
$check[1] = mysql_query("SELECT username FROM Account WHERE username = '$username'");

function user_valid($user)
{
if(!isset($user))
{
$status = 0;
$msg = $msg . "You have not inserted a username <br />";
}
elseif(6 > strlen($user))
{
$status = 0;
$msg = $msg . "Your username must be longer than 5 characters <br />";
}
elseif(strlen($user) > 30)
{
$status = 0;
$msg = $msg . "Your username must be shorter or equal to 30 characters long <br />";
}
else
{
$status = 1;
$msg = $msg . "";
}
}

function pass_valid($pass, $pass2)
{
if(!isset($pass))
{
$status = 0;
$msg = $msg . "You need to enter a password <br />";
}
elseif($pass != $pass2)
{
$status = 0;
$msg = $msg . "Both passwords need to match <br />";
}
elseif( 6 > strlen($pass))
{
$status = 0;
$msg = $msg . "Password must be longer than 5 characters <br />";
}
elseif(strlen($pass) > 32)
{
$status = 0;
$msg = $msg . "Password must be shorter or equal to 32 characters <br />";
}
else
{
$status = 1;
$msg = $msg . "";
}
}

function email_valid($mail)
{
if(!isset($mail))
{
$status = 0;
$msg = $msg . "Email must be entered <br />";
}
elseif(6 > strlen($mail))
{
$status = 0;
$msg = $msg . "Email must be longer than 5 Characters long <br />";
}
elseif(strlen($mail) > 30)
{
$status = 0;
$msg = $msg . "Email must be shorter or equal to 30 characters long <br />";
}
}

function misc_valid($u_name, $e_mail)
{
if(mysql_num_rows($check[0]))
{
$status = 0;
$msg = $msg . "Your email has already been taken. If you have forgotten your password use the forgot password link <br />";
}
elseif(mysql_num_rows($check[1]))
{
$status = 0;
$msg = $msg . "Your chosen username has already been used. Please go back and pick another <br />";
}
else
{
$status = 1;
$msg = $msg . "";
}
}

if(isset($reg) && $reg == "reg258741")
{
$status = 1;
$msg = " ";

user_valid($username);
pass_valid($password, $password2);
email_valid($email);
misc_valid($username, $email);
$md5password = md5($password);

if($status == 0)
{
echo "<color = 'red'>" . $msg . "</color> <br /> <a href = 'register.php'> Go Back and try again </a>";
}
else
{
mysql_query("INSERT INTO Account (username, password, email) VALUES ($username, $md5password, $email)");
echo "<color = 'green'> You have successfully registered <br />";
echo "An email has been sent to the email address provided you will need to activate your account before logging in <br />";
echo "Please <a href = 'login.php'>login here</a>";
}
}
else
{
echo "Please use the registration form";
}
?>

 

config.php

<?

// Database Variables //
$con = mysql_connect("localhost", "*******", "*********");
$db = "********";

// Form Variables //
$username = $_POST['username'];
$password = $_POST['password'];
$password2 = $_POST['password2'];
$email = $_POST['email'];
$terms = $_POST['terms'];
$reg = $_POST['reg258741'];

?>

the error appears in the misc_valid function where im using mysql_num_rows, any help please

Link to comment
https://forums.phpfreaks.com/topic/102917-help-with-signup-script/
Share on other sites

You get that error becuase of an invalid SQL query or you don't have a Mysql connection. Check that your SQL queries are correct.

 

Note: You can't select the username and password independantly, they you need to check the username and password simultainiously.

 

Here is a tutorial about login systems: http://www.phpcodinghelp.com/article.php?article=user-login

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.