|
 |
|
Codewalkers Forums
> PHP Related
> PHP Coding
|
forms - PHP registration and login form
Discuss PHP registration and login form in the PHP Coding forum on Codewalkers. PHP registration and login form Having problems with a PHP script you are coding? This is the place to get help!
|
|
|
|
 |
|
|
|
|

Codewalkers Forums Sponsor:
|
|
|

February 1st, 2013, 08:05 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Location: Denmark
Posts: 13
Time spent in forums: 3 h 3 m 45 sec
Reputation Power: 0
|
|
|
forms - PHP registration and login form
PHP Code:
<?php
require('config.php');
if(isset($_POST['submit'])){
//Perform the verification of the nation
$email1 = $_POST['email1'];
$email2 = $_POST['email2'];
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];
if($email1 == $email2){
if($pass == $pass2){
//All good. Carry on.
}else{
echo "Sorry, your passwords do not match.<br />";
exit();
}
}else{
echo "Sorry your email's do not match<br /><br />";
{
}else{
$form = <<<EOT
<form action="register.php" method="POST">
First Name: <input type="text" name="name" /><br> />
Last Name: <input type="text" name="lname" /><br />
Username: <input type="text" name="uname" /><br />
Email: <input type="text" name="email1" /><br />
Confirm Email: <input type="text" name="email2" /><br />
Password: <input type="text" name="pass1" /><br />
Confirm Password <input type="password" name="pass2" /><br />
<input type="submit" value="Register" name="submit" />
</form>
EOT;
echo $form;
}
?>
Somethings wrong and i don't know what it is please help.
I get an error at
|

February 2nd, 2013, 04:24 AM
|
 |
Contributing User
|
|
Join Date: Apr 2007
Location: Galway
Posts: 1,360

Time spent in forums: 4 Weeks 1 Day 23 h 38 m 14 sec
Reputation Power: 8
|
|
change
Code:
$form = <<<EOT
<form action="register.php" method="POST">
First Name: <input type="text" name="name" /><br> />
Last Name: <input type="text" name="lname" /><br />
Username: <input type="text" name="uname" /><br />
Email: <input type="text" name="email1" /><br />
Confirm Email: <input type="text" name="email2" /><br />
Password: <input type="text" name="pass1" /><br />
Confirm Password <input type="password" name="pass2" /><br />
<input type="submit" value="Register" name="submit" />
</form>
EOT;
echo $form;
to
Code:
<<<EOT
<form action="register.php" method="POST">
First Name: <input type="text" name="name" /><br> />
Last Name: <input type="text" name="lname" /><br />
Username: <input type="text" name="uname" /><br />
Email: <input type="text" name="email1" /><br />
Confirm Email: <input type="text" name="email2" /><br />
Password: <input type="text" name="pass1" /><br />
Confirm Password <input type="password" name="pass2" /><br />
<input type="submit" value="Register" name="submit" />
</form>
EOT;
__________________
When I die, I want to go peacefully like my Grandfather did, in his sleep -- not screaming, like the passengers in his car.
|

February 2nd, 2013, 11:36 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Location: Denmark
Posts: 13
Time spent in forums: 3 h 3 m 45 sec
Reputation Power: 0
|
|
PHP Code:
<?php
require('config.php');
if(isset($_POST['submit'])){
//Perform the verification of the nation
$email1 = $_POST['email1'];
$email2 = $_POST['email2'];
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];
if($email1 == $email2){
if($pass == $pass2){
//All good. Carry on.
}else{
echo "Sorry, your passwords do not match.<br />";
exit();
}
}else{
echo "Sorry your email's do not match<br /><br />";
{
}else{
<<<EOT
<form action="register.php" method="POST">
First Name: <input type="text" name="name" /><br> />
Last Name: <input type="text" name="lname" /><br />
Username: <input type="text" name="uname" /><br />
Email: <input type="text" name="email1" /><br />
Confirm Email: <input type="text" name="email2" /><br />
Password: <input type="text" name="pass1" /><br />
Confirm Password <input type="password" name="pass2" /><br />
<input type="submit" value="Register" name="submit" />
</form>
EOT;
}
?>
Did i do the right thing?
|

February 2nd, 2013, 12:00 PM
|
 |
Contributing User
|
|
Join Date: Apr 2007
Location: Galway
Posts: 1,360

Time spent in forums: 4 Weeks 1 Day 23 h 38 m 14 sec
Reputation Power: 8
|
|
looks about right, might want to display a message to the user to confirm that the update was successful 
|

February 2nd, 2013, 01:22 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Location: Denmark
Posts: 13
Time spent in forums: 3 h 3 m 45 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by DavidMR looks about right, might want to display a message to the user to confirm that the update was successful  |
Still giving me the same errors
At }else{ and ?>
To give you some more info when i run the script it says Parse error: syntax error, unexpected T_ELSE in /website/project/register.php on line 25
|

February 2nd, 2013, 01:29 PM
|
 |
Contributing User
|
|
Join Date: Apr 2007
Location: Galway
Posts: 1,360

Time spent in forums: 4 Weeks 1 Day 23 h 38 m 14 sec
Reputation Power: 8
|
|
Code:
else{
echo "Sorry your email's do not match<br /><br />";
{
your second { should be a }
|

February 2nd, 2013, 01:36 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Location: Denmark
Posts: 13
Time spent in forums: 3 h 3 m 45 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by DavidMR
Code:
else{
echo "Sorry your email's do not match<br /><br />";
{
your second { should be a } |
PHP Code:
}
}else{
echo "Sorry your email's do not match<br /><br />";
{
}else{
Where at i'm kinda new to php scripting.
|

February 2nd, 2013, 01:44 PM
|
 |
Contributing User
|
|
Join Date: Apr 2007
Location: Galway
Posts: 1,360

Time spent in forums: 4 Weeks 1 Day 23 h 38 m 14 sec
Reputation Power: 8
|
|
PHP Code:
}
}else{
echo "Sorry your email's do not match<br /><br />";
{
}else{
should be
PHP Code:
}
}else{
echo "Sorry your email's do not match<br /><br />";
}
}else{
|

February 2nd, 2013, 01:46 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Location: Denmark
Posts: 13
Time spent in forums: 3 h 3 m 45 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by DavidMR
PHP Code:
}
}else{
echo "Sorry your email's do not match<br /><br />";
{
}else{
should be
PHP Code:
}
}else{
echo "Sorry your email's do not match<br /><br />";
}
}else{
|
Works thank you 
|

February 2nd, 2013, 04:07 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Location: Denmark
Posts: 13
Time spent in forums: 3 h 3 m 45 sec
Reputation Power: 0
|
|
PHP Code:
<?php
require('config.php');
if(isset($_POST['submit'])){
//Perform the verification of the nation
$email1 = $_POST['email1'];
$email2 = $_POST['email2'];
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];
if($email1 == $email2){
if($pass == $pass2){
//All good. Carry on.
$name = mysql_escape_string($_POST['name']);
$lname = mysql_escape_string($_POST['lname']);
$uname = mysql_escape_string($_POST['uname']);
$email1 = mysql_escape_string($email1);
$email2 = mysql_escape_string($email2);
$pass1 = mysql_escape_string($pass1);
$pass2 = mysql_escape_string($pass2);
$pass1 = md5($pass1);
mysql_query("INSERT INTO 'users' ('id', 'name', 'lname', 'uname', 'email', 'pass') VALUES (NULL, '$name', '$lname', '$uname', '$email1', '$pass1')") or die(mysql_error());
}else{
echo "Sorry, your passwords do not match.<br />";
exit();
}
}else{
echo "Sorry your email's do not match<br /><br />";
}
}else{
<<<EOT
<form action="register.php" method="POST">
First Name: <input type="text" name="name" /><br> />
Last Name: <input type="text" name="lname" /><br />
Username: <input type="text" name="uname" /><br />
Email: <input type="text" name="email1" /><br />
Confirm Email: <input type="text" name="email2" /><br />
Password: <input type="text" name="pass1" /><br />
Confirm Password <input type="password" name="pass2" /><br />
<input type="submit" value="Register" name="submit" />
</form>
EOT;
}
?>

|

February 2nd, 2013, 04:16 PM
|
 |
Contributing User
|
|
Join Date: Apr 2007
Location: Galway
Posts: 1,360

Time spent in forums: 4 Weeks 1 Day 23 h 38 m 14 sec
Reputation Power: 8
|
|
|
the code looks ok, try removing "spaces" from before those lines to eliminate dodgy characters messing up your script.
|

February 2nd, 2013, 04:33 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Location: Denmark
Posts: 13
Time spent in forums: 3 h 3 m 45 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by DavidMR the code looks ok, try removing "spaces" from before those lines to eliminate dodgy characters messing up your script. |
PHP Code:
<?php
require('config.php');
if(isset($_POST['submit'])){
//Perform the verification of the nation
$email1 = $_POST['email1'];
$email2 = $_POST['email2'];
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];
if($email1 == $email2){
if($pass == $pass2){
//All good. Carry on.
$name = mysql_escape_string($_POST['name']);
$lname = mysql_escape_string($_POST['lname']);
$uname = mysql_escape_string($_POST['uname']);
$email1 = mysql_escape_string($email1);
$email2 = mysql_escape_string($email2);
$pass1 = mysql_escape_string($pass1);
$pass2 = mysql_escape_string($pass2);
$pass1 = md5($pass1);
mysql_query("INSERT INTO 'users' ('id', 'name', 'lname', 'uname', 'email', 'pass') VALUES (NULL, '$name', '$lname', '$uname', '$email1', '$pass1')") or die(mysql_error());
}else{
echo "Sorry, your passwords do not match.<br />";
exit();
}
}else{
echo "Sorry your email's do not match<br /><br />";
}
}else{
<<<EOT
<form action="register.php" method="POST">
First Name: <input type="text" name="name" /><br> />
Last Name: <input type="text" name="lname" /><br />
Username: <input type="text" name="uname" /><br />
Email: <input type="text" name="email1" /><br />
Confirm Email: <input type="text" name="email2" /><br />
Password: <input type="text" name="pass1" /><br />
Confirm Password <input type="password" name="pass2" /><br />
<input type="submit" value="Register" name="submit" />
</form>
EOT;
}
?>
|

February 2nd, 2013, 04:39 PM
|
 |
Contributing User
|
|
Join Date: Apr 2007
Location: Galway
Posts: 1,360

Time spent in forums: 4 Weeks 1 Day 23 h 38 m 14 sec
Reputation Power: 8
|
|
|
echo your query just before you run it? (its horrible coding practice to run a query with mysql_query without a check)
|

February 2nd, 2013, 05:02 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Location: Denmark
Posts: 13
Time spent in forums: 3 h 3 m 45 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by DavidMR echo your query just before you run it? (its horrible coding practice to run a query with mysql_query without a check) |
PHP Code:
<?php
require('config.php');
if(isset($_POST['submit'])){
//Perform the verification of the nation
$email1 = $_POST['email1'];
$email2 = $_POST['email2'];
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];
if($email1 == $email2){
if($pass == $pass2){
//All good. Carry on.
$name = mysql_escape_string($_POST['name']);
$lname = mysql_escape_string($_POST['lname']);
$uname = mysql_escape_string($_POST['uname']);
$email1 = mysql_escape_string($email1);
$email2 = mysql_escape_string($email2);
$pass1 = mysql_escape_string($pass1);
$pass2 = mysql_escape_string($pass2);
$pass1 = md5($pass1);
echo mysql_query("INSERT INTO 'users' ('id', 'name', 'lname', 'uname', 'email', 'pass') VALUES (NULL, '$name', '$lname', '$uname', '$email1', '$pass1')") or die(mysql_error());
}else{
echo "Sorry, your passwords do not match.<br />";
exit();
}
}else{
echo "Sorry your email's do not match<br /><br />";
}
}else{
<<<EOT
<form action="register.php" method="POST">
First Name: <input type="text" name="name" /><br> />
Last Name: <input type="text" name="lname" /><br />
Username: <input type="text" name="uname" /><br />
Email: <input type="text" name="email1" /><br />
Confirm Email: <input type="text" name="email2" /><br />
Password: <input type="text" name="pass1" /><br />
Confirm Password <input type="password" name="pass2" /><br />
<input type="submit" value="Register" name="submit" />
</form>
EOT;
}
?>
|

February 3rd, 2013, 06:27 AM
|
 |
Contributing User
|
|
Join Date: Apr 2007
Location: Galway
Posts: 1,360

Time spent in forums: 4 Weeks 1 Day 23 h 38 m 14 sec
Reputation Power: 8
|
|
|
like this? what?
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|