Jump to content

[SOLVED] A silly Mistake?


Accurax

Recommended Posts

Ive been staring at this for the last hour and i cant see where the mistake is.... ive had it working before.

This morning i added the if statement, as i wanted to get new members to type there password twice.

It all seems to work, except that it wont actually enter the info into the database, it just drops to the or die statment, can anyone see what ive done worng please?

[code]
<?php
include("info.inc");

$connection=mysql_connect($host, $user, $passwd)
or die ("Could not connect !");
$db = mysql_select_db($database, $connection)
or die ("Could not connect to Database");

$username = $_POST['username'];
$password = $_POST['password'];
$password2 = $_POST['password2'];
$usermail = $_POST['usermail'];

if ( $password == $password2)
{
$pass = md5($password);
$key = md5($user_name);

$query = "INSERT INTO members (user_name, email, password, key)
VALUES ('$username', '$usermail', '$pass', '$key')";
$result = mysql_query($query)
or die ("could not add user.");
}
else
{
header("location: passnomatch.php");
}

?>[/code]
Link to comment
Share on other sites

Try putting backticks aroud the word [i]key[/i], I believe it to be a reserved word.

[code=php:0]
$query = "INSERT INTO members (user_name, email, password, `key`) VALUES ('$username', '$usermail', '$pass', '$key')";
[/code]
Link to comment
Share on other sites

OK.

Can't see the form so make sure that has the correct fields.

when comparing strings try using strcmp($password, $password2) == 0 (I think thats just good practice!)

BUT the one thing that kills it is $key=md5($user_name);

you have no $user_name - just $username so I suspect the key field in your database is not null and has no default value it will always get the md5 of null.

PS Just read thorpes - key is indeed a reserved word!!!
Link to comment
Share on other sites

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.