Jump to content

Name and password verification


Thesus

Recommended Posts

Well I'm trying to create a forum and have been doing so for a while, I just can never verify the user's password correctly. If they haven't been inserted into the database, it automatically assumes the names and password do not match. I thought I finally figured it out with this simplified-down code, but currently to no avail I just get a blank page. Help's very, very, very much appreciated. :P (Just to note aswell, this isn't a register/login forum. It's where you use a name and password, and that's it- no login)

[code]
<?php
$host="db1.awardspace.com";
$username="thesus_dantee";
$password="*********";
$db_name="thesus_dantee";
$tbl_name="regulars";

mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$name1 = $_POST['name'];
$password1 = $_POST['password'];

$name = addslashes('$name1');
$password = addslashes('$password1');

$check = "SELECT name FROM $tbl_name WHERE name='$name'";
$query = mysql_query($check);

if($query == 0){
$sql = "INSERT INTO $tbl_name(name, password)VALUES('$name', '$password')";
$result = mysql_query($sql);
echo "Successfully Posted!";
}
else
{
$check2 = "SELECT * FROM $tbl_name WHERE name='$name' AND password='$password'";
$query2 = mysql_query($check2);

$count = mysql_num_rows($query2);

if($count == 1){
$sql2="INSERT INTO $tbl_name(name, password)VALUES('$name', '$password')";
$result2=mysql_query($sql2);
echo "Sucessfully Posted!";
}
}
?>
[/code]
Link to comment
Share on other sites

The logic in your script seems odd.  At the end, with $query2, you say "If the user and password exist in the database, then insert them again".  That doesn't make sense.  If they are already in the database, then any attempt to insert them will fail.  It should probably be

[code]if ($count == 1) {
  echo "Username and password match!";
}[/code]

Also, it's a good idea to check the result of your second mysql query, just in case.

[code]if ($query2 === false) {
  die("$query2 failed: " . mysql_error());
}[/code]

In this case, $query2 == 0 will give you the same result.
Link to comment
Share on other sites

When you check the database for the name and password, and if that person has never postd before and has no information stored, it automatically assumes the name and password are incorrect and doesn't alow you to post. So the first query checks if the name is, infact there, and if it isn't it allows you to post and stores your password for the 2nd query for future postage. :D

And thanks, I'll try, and hopefully it'll work. :p
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.