PDA

View Full Version : Video Tutorial - Login Script #1


owner
09-03-2007, 04:31 AM
Hello,

I am having some troubles with the login script 1st tutorial.

I am not getting any errors, but for some reason, when I hit my submit button, the script cannot find the user that I have in my mySQL database.

Here is the code I am using.

<?php
require_once("./connection.php"); //Database Connection

//Catch Field Data
$userid = $_POST['userid'];
$password = $_POST['passowrd'];
$submitted = $_POST['submitted'];

if ($userid && $password) {
/////////////////////////////////////////////
$query = sprintf("SELECT * FROM users where user_name='$userid' and user_password = '$userpassword'");
$result = @mysql_query($query);
$rowAccount = @mysql_fetch_array($result);
/////////////////////////////////////////////
}

if ($rowAccount){

echo "The record exists so you can enter";

}elseif($submitted){

echo "You dont exist in the system, so sucks to be you, but your not getting in!";

}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<form id="form1" name="form1" method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<p>&nbsp;</p>
<p>&nbsp;</p>
<table width="259" height="172" border="1" align="center">
<tr>
<td width="82" height "45">User ID</td>
<td width="161"> <input name="userid" type="text" id="userid" /> </td>
</tr>
<tr>
<td width="82" height "45">Password</td>
<td width="161"> <input name="password" type="text" id="password" maxlength="26"> </td>
</tr>
<tr>
<td width="82" height "45">Log Me In Scotty!</td>
<td width="161"> <div align="center">
<input name="submitted" type="hidden" id="submitted" value="1" />
<input type="submit" name="submit" value="Login" />
</div></td>
</tr>
</table>
</form>
</body>
</html>
I do have the connection.php file configured right. (I am 99.9% sure :D)

Also, I do have an account made in the database. I can post a screenshot up of that too, if you need that.

Please help,
Thanks,
-Owner

owner
09-03-2007, 06:15 AM
Lol, why cant I edit my post :(

Anyways, Figured it out. If you look closely you will find the error I made too ;)

davidj
09-03-2007, 09:36 AM
nice one

now dont you feel like a right plum when that happens

owner
09-03-2007, 03:51 PM
Yes, I do feel a bit flawed :P

But, I do have another question.

In
Part 9 - Inserting data with PHP (http://www.dreamweaverclub.com/forum/../vtm/)


What is the code that is in the php wrappers in the table with the ID1, data2, data3, data4?

Thanks for everything so far!
Your tutorials are awesome!

From my knowledge, it is going to be something like,

<?php echo '$id'; ?>
<?php echo '$data2'; ?>
and so on

am I correct?

davidj
09-03-2007, 03:55 PM
i think this is what your after....


<? echo $rowAccount['db_column']; ?>



Your tutorials are awesome!


the ladies think im a bit special as well in a certain department

owner
09-03-2007, 03:56 PM
Haha,

and wow that was the fastest reply for help I think i've ever gotten lol :D

owner
09-03-2007, 06:59 PM
<? echo $rowAccount['db_column']; ?>


Ok, I tried this, but it only displays the 1st row in the mysql database.

Example: I have 3 id's

1-3 full of information

This is only displaying id #1 information but not 2 and 3. How would I get this to display all of the rows in the database?

EDIT: I forgot to loop it. So here is an example code.

<?
do {
echo '<tr><td height="21" valign="top">'.$row['data2'];
} while ($row = mysql_fetch_array($result));
echo '</td></tr>';
?>

davidj
09-04-2007, 09:32 AM
so is it working now

owner
09-05-2007, 01:47 PM
Yup, flawless!