Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
* * * * * 2 votes

Creating login/registration forms with PHP

registration form registration login

  • Please log in to reply
105 replies to this topic

#25 kartikssj

kartikssj

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 15 September 2009 - 11:36 AM

nice!
  • 0

#26 hudbarnett

hudbarnett

    CC Newcomer

  • Just Joined
  • PipPip
  • 23 posts

Posted 21 January 2010 - 09:17 AM

Hi there

I am totally new to php and i have setup the database and created a user and password. I have seen in the script where i put the username and databse name but i can't see where the password goes. Can anyone help...

<?php
session_start();session_destroy();
session_start();
if($_GET["regname"] && $_GET["regemail"] && $_GET["regpass1"] && $_GET["regpass2"] )
{
if($_GET["regpass1"]==$_GET["regpass2"])
{
$servername="localhost";
$username="root";
$conn= mysql_connect($servername,$username)or die(mysql_error());
mysql_select_db("test1",$conn);
$sql="insert into users (name,email,password)values('$_GET[regname]','$_GET[regemail]','$_GET[regpass1]')";
$result=mysql_query($sql,$conn) or die(mysql_error());
print "<h1>you have registered sucessfully</h1>";

print "<a href='index.php'>go to login page</a>";
}
else print "passwords doesnt match";
}
else print"invaild input data";

?>

Edited by Orjan, 21 January 2010 - 09:22 AM.
Please use code tags for your code!

  • 0

#27 k1net1cs

k1net1cs

    CC Newcomer

  • Just Joined
  • PipPip
  • 20 posts

Posted 30 January 2010 - 02:04 AM

@hudbarnett

I don't really get what you're trying to ask, but I'll try to answer.


$sql="insert into users (name,email,password) values ('$_GET[regname]','$_GET[regemail]','$_GET[regpass1]')";

According to the SQL syntax above, the data from the registration form is inserted to a table named users, which has fields (or columns) named name, email & password.

$_GET[regname]'s value goes to the name column.
$_GET[regemail]'s value goes to the email column.
$_GET[regpass1]'s value goes to the password column.

Also, if I may enhance that rough code of yours :


<?php
session_start();
session_unset();

if(isset($_GET["regname"],$_GET["regemail"],$_GET["regpass1"],$_GET["regpass2"]))
{
if($_GET["regpass1"] == $_GET["regpass2"])
{
$servername = "localhost";
$username = "root";
$conn = mysql_connect($servername,$username) or die('Could not connect : ' . mysql_error());

mysql_select_db("test1");

$sql = "INSERT INTO `users` VALUES ('$_GET[regname]','$_GET[regemail]','$_GET[regpass1]')";
$result = mysql_query($sql) or die('Could not insert values : ' . mysql_error());

mysql_close();

print "<h1>You have registered sucessfully.</h1><br><br>";
print "Go to <a href='index.php'>login page</a>.";
}
else
print "Passwords don't match.";
}
else
print "Invalid input data.";
?>

Of course, these amendments of mine may not be optimal and/or may contain an error or two, but please do correct me if I'm wrong.
  • 0

#28 so1i

so1i

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 297 posts

Posted 30 January 2010 - 02:56 AM

Hi there

I am totally new to php and i have setup the database and created a user and password.


You put the password for the database in the connection string along with $servername and $username, so it would be in this line:

$conn = mysql_connect($servername,$username,$password) or die('Could not connect : ' . mysql_error());


Hope that helps!
  • 0

#29 Guest_Jaan_*

Guest_Jaan_*
  • Guest

Posted 30 January 2010 - 04:23 AM

Well.. I suggest if you have finished your code, remove those "mysql()" errors because they are good information for hackers :)
  • 0

#30 k1net1cs

k1net1cs

    CC Newcomer

  • Just Joined
  • PipPip
  • 20 posts

Posted 30 January 2010 - 06:29 AM

@so1i
Ah, so that's what he really meant...
Nothing screws my head more than hours of Dragon Age, I guess... =b

@hudbarnett
Like Jaan said, those die() functions should not contain mysql_error() function anymore if the website is accessible by the public.
It's still fine if you just want to test things out in your own computer, though.
Might as well looking up some techniques in input validation, especially using regular expressions (regex).
  • 0

#31 st_holysinner

st_holysinner

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 14 February 2010 - 05:20 AM

i downloaded the attached files for this. when i run registration it says Table 'test.users' doesn't exist.. help me pls..
  • 0

#32 Edhouse

Edhouse

    CC Lurker

  • Just Joined
  • Pip
  • 6 posts

Posted 15 February 2010 - 12:29 AM

I also thank for this tutorial. :)
  • 0

#33 kailas

kailas

    CC Newcomer

  • Just Joined
  • PipPip
  • 15 posts

Posted 15 February 2010 - 07:37 AM

To create registration forms can be used PHP Form. It is convenient and simple.
  • 0

#34 WhySG.com

WhySG.com

    CC Lurker

  • Just Joined
  • Pip
  • 3 posts

Posted 12 April 2010 - 04:03 AM

After I entered the details in the registration form, and pressed next, nothing showed up.

Using firefox, windows 7, apache 2, php5............

anyone has any idea?

Edited by WhySG.com, 13 April 2010 - 01:12 AM.

  • 0

#35 kasha

kasha

    CC Lurker

  • Just Joined
  • Pip
  • 9 posts

Posted 16 April 2010 - 09:39 AM

After I entered the details in the registration form, and pressed next, nothing showed up.

Using firefox, windows 7, apache 2, php5............

anyone has any idea?


Have u checked that the location of the registration.php file is in the same directory/location as your registration form?
  • 0

#36 WhySG.com

WhySG.com

    CC Lurker

  • Just Joined
  • Pip
  • 3 posts

Posted 16 April 2010 - 08:26 PM

Have u checked that the location of the registration.php file is in the same directory/location as your registration form?

yup.......... i've checked. weird since it does not work. doesnt seem to input details into db also i think. but no error message.
  • 0





Also tagged with one or more of these keywords: registration form, registration, login