I'm trying to make a PHP MySQL login form. For some reason the php portion of the code always returns a blank page. When I type in a username or pass, the next page doesn't do what I need it to. I used WampServer to make sure I installed everything correctly. Does anyone know what the problem is?

Thank you so much for any help, it is greatly appreciated!

Here are my codes

userLogin.html

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

</head>

<body >

<form method="post" action="userLogin.php" >

<table border="1" >

<tr>

<td>

<B>User-Id</B>

</td>

<td><input type="text" name="userid">

</tr>

<tr>

<td><B>Password</B></td>

<td><input name="password" type="password"></input></td>

</tr>

<tr>

<td><input type="submit" value="Submit"/>

<td><input type="reset" value="Reset"/>

</tr>

</table>

</form>

</body>

</html>

userLogin.php

<?php

$f_usr= $_POST["userid"];

$f_pswd= $_POST["password"];

$con=mysql_connect("localhost","root","");

if(! $con)

{

    die('Connection Failed'.mysql_error());

}

mysql_select_db("dave",$con);

$result=mysql_query("select * from user");

while($row=mysql_fetch_array($result))

{

if($row["username"]==$f_usr && $row["password"]==$f_pswd)

    echo"Welcome";

else

    echo"Sorry";

}

?>

    Check your php.ini. You should enable error reporting. Google how to do that.
    Meanwhile, put this at the beginning of the php file:

    ini_set('display_errors', 1);
    error_reporting(E_ALL);
    
    // rest of the code

    Also, change to this:

    $result=mysql_query("select * from user") or die(mysql_error()); 

    Most likely that the table name is "users", not "user", but that's a wild guess.

      Also note that in your code snippet above, if the table has no rows, then your script will not output anything.

        Hi

        Do you need curly braces and round brackets around { echo("Welcome"); } and { echo("Sorry"); } ?

        Chris

          cneeds;10964621 wrote:

          Hi

          Do you need curly braces and round brackets around { echo("Welcome"); } and { echo("Sorry"); } ?

          Chris

          No, they are not necessary (though some still add them due to style/personal preference).

            Write a Reply...