Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy. This forum is not for asking programming related questions.
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.
<?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;
?>
Sorry, a bit confused with your comment. Does that mean in php 5, I cannot start a session within my register.php? So should I only start the sessions when the login, in login.php?
is placed at the very top of each php page which begins and continues your session. Whitespace is not allowed at the beginning of your php it may cause an error.