Jump to content

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]

Link to comment
https://forums.phpfreaks.com/topic/10966-help-with-a-register-form/
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.
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\" /]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.