Jump to content

Archived

This topic is now archived and is closed to further replies.

nphls

Help with a register form

Recommended Posts

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.

[code]<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>[/code]

Share this post


Link to post
Share on other sites
You might have an error in your SQL query. To find out chnage the following code:[code]$results = mysql_query($request);


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

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

echo "Succesfully registered!";[/code]
If there is a problem with the sql query then you'll get an [i]Unable to perform query message[/i] 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.

Share this post


Link to post
Share on other sites
Thanks for your help.
The error was in synthax.

I had this:

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

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\" /]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.