View Full Version : Why wont my login work? =[

02-14-2008, 11:13 PM
I got an online tutorial on how to creat a php login thing. And for some reason i cant get it to work, i'll give you all a pic of my database name, and see if you can help me connect to it.


This is the code im using to connect, but i think my database name is wrong( Please tell me how to fix the name also):

// Replace the variable values below
// with your specific database information.
$host = "";
$user = "";
$pass = "";
$db = "";
// This part sets up the connection to the
// database (so you don't need to reopen the connection
// again on the same page).
$ms = mysql_pconnect($host, $user, $pass);
if ( !$ms )
echo "Error connecting to database.\n";
// Then you need to make sure the database you want
// is selected.

also, this is the register page im using, any ideas on how to improve this:
// dbConfig.php is a file that contains your
// database connection information. This
// tutorial assumes a connection is made from
// this existing file.
include ("dbConfig.php");

//Input vaildation and the dbase code
if ( $_GET["op"] == "reg" )
$bInputFlag = false;
foreach ( $_POST as $field )
if ($field == "")
$bInputFlag = false;
$bInputFlag = true;
// If we had problems with the input, exit with error
if ($bInputFlag == false)
die( "Problem with your registration info. "
."Please go back and try again.");
// Fields are clear, add user to database
// Setup query
$q = "INSERT INTO `dbUsers` (`username`,`password`,`email`) "
."VALUES ('".$_POST["username"]."', "
."PASSWORD('".$_POST["password"]."'), "
// Run query
$r = mysql_query($q);

// Make sure query inserted user successfully
if ( !mysql_insert_id() )
die("Error: User not added to database.");
// Redirect to thank you page.
Header("Location: register.php?op=thanks");
} // end if

//The thank you page
elseif ( $_GET["op"] == "thanks" )
echo "<h2>Thanks for registering!</h2>";

//The web form for input ability
echo "<form action=\"?op=reg\" method=\"POST\">\n";
echo "Username: <input name=\"username\" MAXLENGTH=\"16\"><br />\n";
echo "Password: <input type=\"password\" name=\"password\" MAXLENGTH=\"16\"><br />\n";
echo "Email Address: <input name=\"email\" MAXLENGTH=\"25\"><br />\n";
echo "<input type=\"submit\">\n";
echo "</form>\n";
// EOF

EDIT: I can now connect to my Database but it still says "User not entered into database" I think I'm telling it to enter the user in the wrong table or whatever.

Thanks so much,

Andrew Johnson
02-14-2008, 11:18 PM
Posting your database ip/user/pass is a BAD idea.

Where is your login code? I only see register and connect.

Deacon Frost
02-14-2008, 11:37 PM
like he said, it's a bad idea...

but my thought is.. if you are using MySQL... it takes the name of your account (Say you signed up with michael) and it attaches that to like... everything.

So it'd be michael_loginthingy or michael_dbuser

try that

02-15-2008, 12:50 AM
Fixed the problem guys, thanks