Issues with php register
Posted: Mon Nov 16, 2009 1:22 pm
Hi. So I am creating a register script, which currently has some issues I am trying to Iron out. My first issue is that it my form takes four fields, username, password, confirm password and email. However, it is currently letting me register someone with just putting in a username. How do I get an error thrown If any of the inputs are empty?
I will show my php code as it may help, and I will problably have more questions after.
cheers
I will show my php code as it may help, and I will problably have more questions after.
cheers
Code: Select all
<?php
/*Use of Sessions*/
if(!session_id())
session_start();
header("Cache-control: private"); //avoid an IE6 bug (keep this line on top of the page)
$login='ERROR';
/*simple checking of the data*/
if(isset($_POST['login']) && isset($_POST['pass']) && ($_POST['pass'] == $_POST['confirm']))
{
/*Connection to database logindb using your login name and password*/
$db=mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('webusers');
/*additional data checking and striping*/
$_POST['login']=mysql_real_escape_string(strip_tags(trim($_POST['login'])));
$_POST['pass']=mysql_real_escape_string(strip_tags(trim($_POST['pass'])));
$_POST['email']=mysql_real_escape_string(strip_tags(trim($_POST['email'])));
mysql_query("INSERT INTO login SET login='{$_POST['login']}',pass='{$_POST['pass']}',email='{$_POST['email']}'",$db);
/*If the database has been updated*/
if(mysql_affected_rows() > 0)
{
$_SESSION['login'] = $_POST['login'];
$login='You are now registered '.$_SESSION['login'];
echo '<p><a href="shop.html">LOGIN</a></p>';
}
else
{
$login= 'This login name already exists.';
echo '<p><a href="shop.html">Go back and try again</a></p>';
}
mysql_close($db);
}
//you may echo the data anywhere in the file
echo $login;
?>