Issues with php register

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.

Moderator: General Moderators

Post Reply
nick2price
Forum Newbie
Posts: 18
Joined: Fri Nov 13, 2009 5:49 pm

Issues with php register

Post by nick2price »

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

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;
?>
User avatar
akuji36
Forum Contributor
Posts: 190
Joined: Tue Oct 14, 2008 9:53 am
Location: Hartford, Connecticut

Re: Issues with php register

Post by akuji36 »

Hello

take a look at the following:

http://www.slideshare.net/sanjay/presen ... kies-php-5

Please note that in php 5 you cannot use register to
begin sessions.

thanks

Rod
nick2price
Forum Newbie
Posts: 18
Joined: Fri Nov 13, 2009 5:49 pm

Re: Issues with php register

Post by nick2price »

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?

cheers
User avatar
akuji36
Forum Contributor
Posts: 190
Joined: Tue Oct 14, 2008 9:53 am
Location: Hartford, Connecticut

Re: Issues with php register

Post by akuji36 »

Hello

That is correct. In php 5 you cannot use register to start your sessions.

I began learning php using php 4 which allowed register session.

In php 5 you begina a session like this:

http://www.trans4mind.com/personal_deve ... nStart.htm

and

Code: Select all

<?php
 
session_start();
 
?>
 
 
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.



thanks

Rod :)
Post Reply