Jump to content


Photo

Help with a register form


  • Please log in to reply
2 replies to this topic

#1 nphls

nphls
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 01 June 2006 - 03:47 PM

I have a problem with a "registration form".
The problem is that i cant enter the data into the MySQL database.
I enter the data in the form correctly and then it goes to "registered.php" where it sould introduce the data in the database.
Here's the code. At the end of it there's an IF for me to know if the data was inserted or no in the database. I always get "Not registered".

Where's the mistake? Can you help me, because i just don't know where it is.

<HTML>
<HEAD>
 <TITLE>Registered.php</TITLE>
</HEAD>
<BODY>

<?

$user = $_POST['username'];
$pass = $_POST['password'];
$email = $_POST['email'];
$name = $_POST['name'];
$country = $_POST['country'];
$city = $_POST['city'];

////////////////////////////////////////////////////////////////////////////////

$host = 'localhost';
$username = 'root';
$database = 'project';
$password = '';

$connect = mysql_connect($host,$username,$password) or
die("Error connecting to Database! " . mysql_error());
mysql_select_db($database , $connect) or die("Cannot select database! " . mysql_error());
$request = "INSERT INTO users values(NULL,'$user','$pass','$email','$name','$country','$city',)";
$results = mysql_query($request);


if($results)
{
echo "Registered"
}
else
{
echo "Not Registered";

}
mysql_close($connect);
Die();

?>

</BODY>
</HTML>



#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 01 June 2006 - 04:07 PM

You might have an error in your SQL query. To find out chnage the following code:
$results = mysql_query($request);


if($results)
{
echo "Registered"
}
else
{
echo "Not Registered";

}
to the following:
$results = mysql_query($request) or die("Unable to perform query: " . $result . "<br /><br />" . mysql_error());

echo "Succesfully registered!";
If there is a problem with the sql query then you'll get an Unable to perform query message when you next run the code. If you dont understand the error message that may be shown you can post it here and we'll be able to help.

#3 nphls

nphls
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 01 June 2006 - 06:08 PM

Thanks for your help.
The error was in synthax.

I had this:

$request = "INSERT INTO users values(NULL,'$user','$pass','$email','$name','$country','$city',)";

I just removed the comma after $city. However, thanks a lot for your help, otherwise i would'nt have found that error.

[img src=\"style_emoticons/[#EMO_DIR#]/wink.gif\" style=\"vertical-align:middle\" emoid=\":wink:\" border=\"0\" alt=\"wink.gif\" /]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users