Register

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
TheCase
Forum Newbie
Posts: 8
Joined: Fri Jan 05, 2007 1:19 am

Register

Post by TheCase »

Hi,

My register script is not working it echo's You could not be registered due to a system error. We apologize for any inconvenience. I think it's around the query

Code: Select all

mysql_query ("INSERT INTO 'login' (`username`,`email`,`password`) VALUES ('$username','$email',SHA('$password'))");  
}
but i've been trying for hours here is the code bellow. Thanks

Code: Select all

<?php 

//// 
// Connect to the Database 
//// 

include_once ('./db_connect.php'); 

//// 
// Handle the form. 
//// 

if (isset($_POST['submit'])) { 
      
//// 
// Check for a username 
//// 

if (eregi ('^[[]\.\'\-] {2,15}$', stripslashes(trim($_POST['username'])))) { 
$username = FALSE; 
echo '<p><font color="red" size="+2"> Please enter a username</font></p>'; 
     } 

//// 
// Check for a email 
//// 

if (eregi ('^[[]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['email'])))) { 
$email = escape_data($_POST['email']); 
} else { 
$email = FALSE; 
echo '<p><font color="red" size="+2"> Please enter a vaild email</font></p>'; 
} 

//// 
// Check for password and match confirmed password 
//// 

if (eregi ('^[[]]{4,20}$',stripslashes(trim($_POST['password1'])))){ 
if ($_POST['password1'] == $_POST['password2']) { 
$password = escape_data($_POST['password1']); 
}else{ 
$password = FALSE; 
echo '<p><font color="red" size="+2">Your password did not match</font></p>'; 
} 
  
if ($username && $email && $password) { 
} 

//// 
// Add the user 
//// 

mysql_query ("INSERT INTO 'login' (`username`,`email`,`password`) VALUES ('$username','$email',SHA('$password'))"); 
} 
//// 
// Thank you page 
//// 

echo '<h3>Thank you for registering to the website. You can now log into the website.'; 
exit(); 

} else { 
echo '<p><font color="red" size"+2">You could not be registered due to a system error. We apologize for any inconvenience.</font></p>'; 
} 

mysql_close(); 

?> 

<h1>Register</h1> 
<form action="register.php" method="post"> 
<fieldset> 

<p><b>Username:</b> <input type="text" name="username" size="15" maxlength="15" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>" /></p> 

<p><b>Email:</b> <input type="text" name="email" size="40" maxlength="40" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /></p> 

<p><b>Password:</b> <input type="password" name="password1" size="20" maxlength="20" /></p> 

<p><b>Confirm Password:</b> <input type="password" name="password2" size="20" maxlength="20" /></p> 

</feildset> 

<div align="center"><input type="submit" name"submit" value="Register" /></div> 
<input type="hidden" name="submit" value="TRUE" /> 

</form>
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

Wild guess here, is your form method POST? If so, is your submit button named "submit"?

Code: Select all

<input type="submit" name="submit" />
Aside from that, your error checking looks pretty bad... if you used indenting you'd have a better grasp on where the problems are. It's hard to keep track of all that when you're pasting in code, but indenting will help - I promise!
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

Some Assumptions I made, tell me if these are right I guessed the code you posted is of register.php
If that is so, it always displays on the top of the line saying the

Code: Select all

You could not be registered due to a system error. We apologize for any inconvenience.
Always on the top of the html form. This happens because of the

Code: Select all

if (isset($_POST['submit'])) { 
....
...
}else{
...
 echo "You could not be registered due to a system error. We apologize for any inconvenience.
";
}
<form>...........
</form>
When anybody opens normally that register.php page by default it is in else loop and shows that message normally
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

Your form is in the same file as your form handling code? I just assumed you posted them here together.

Every time a PHP file is run, ALL the code is run.

When you first call the page:

Code: Select all

if (isset($_POST['submit'])) { // THERE IS NO $_POST['submit'] VARIABLE SET.....
....
...
}else{ // ....SO THE SCRIPT WILL EXECUTE THIS BLOCK:
...
 echo "You could not be registered due to a system error. We apologize for any inconvenience.
";
}
TheCase
Forum Newbie
Posts: 8
Joined: Fri Jan 05, 2007 1:19 am

Post by TheCase »

Kieran Huggins wrote:Your form is in the same file as your form handling code? I just assumed you posted them here together.

Every time a PHP file is run, ALL the code is run.

When you first call the page:

Code: Select all

if (isset($_POST['submit'])) { // THERE IS NO $_POST['submit'] VARIABLE SET.....
....
...
}else{ // ....SO THE SCRIPT WILL EXECUTE THIS BLOCK:
...
 echo "You could not be registered due to a system error. We apologize for any inconvenience.
";
}

This is great. It's all one code also. the $_POST['submit'] is defining it there and then ... because to define a field box you do

$feildbox = $_POST['name']; so I thought if you do it in the script it will work? How do I define it then. Also

Your form is in the same file as your form handling code? I just assumed you posted them here together.

No thats just the register.php script when the reason why I put it as handling is because it has the query in and then echo's the thank you page. This is all one script. Hope you understand this, thanks for the help
TheCase
Forum Newbie
Posts: 8
Joined: Fri Jan 05, 2007 1:19 am

Post by TheCase »

Waw, it works finally. I managed to get it work. Now all that I got left is when I view the page before I submit it, it is echoing

"You could not be registered due to a system error. We apologize for any inconvenience."

Then I hit submit and everything works. Thanks
Post Reply