Hey folks, I'm trying to create my first Login script using php to check for username and password in a MYSQL database. The script seems succesful at connecting to the database, however when I retrieve results from a table that I have confrimed exsist, the mysql_num_rows($result); returns zero, Can anyone suggest a solution or a diagnosis path?
Here is what I have:
LAMP server
PHP 5.4.4-7
MYSQL Ver 14.14 Distrib 5.5.24
<?php
ob_start();
$host="localhost"; // Host name
$username="pi"; // Mysql username
$password="raspberry"; // Mysql password
$db_name="n2it2_database"; // Database name
$tbl_name="email_list"; // Table name
// Connect to server and select databse.
$dbc = mysqli_connect("$host", "$username", "$password", "$db_name")or die("cannot connect");
$sql="SELECT * FROM email_list";
$result=mysqli_query($dbc, $sql) or die('Error quering database.');
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
echo "Success!";
}
else {
echo "Wrong Username or Password";
}
ob_end_flush();
?>
login_script 2.php