I am very sorry if this is a noob question, but I am very new to php and mysql, and I greatly appreciate any people who could help me.
I have a script to get the login from the user:
<?php
$host="localhost"; // Host name
$username="JP"; // Mysql username
$password="password"; // Mysql password
$db_name="chatduex"; // Database name
$tbl_name="users"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from form
$myusername=$_POST['namech'];
$mypassword=$_POST['passwordch'];
//check $myusername & $mypassword for fishiness!!
echo '$myusername::::::::::::';
echo $myusername;
echo'<br>';
//fishiness tropers! Inspect $mypassword for fishiness!!
//Yessir!! Yes! Sir!
//10 hut!!
echo '$mypassword:::::::::::';
echo $mypassword;
echo '<br>';
// To protect MySQL injection (more detail about MySQL injection)
//$myusername = stripslashes($myusername);
//$mypassword = stripslashes($mypassword);
//$myusername = mysql_real_escape_string($myusername);
//$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE name='$myusername' and password='$mypassword'";
//Check Everything!!! ...Just in case!!
echo 'SQL code:::::: ';
echo $sql;
echo '<br>';
//Check connection to database for $result!! Johntropers! Use $conn!!
require_once 'login.php';
$conn = new mysqli($hn, $un, $pw, $db);
echo 'Froggy <br>';
if ($conn->connect_error) die($conn->connect_error);
$connnn = mysql_connect('localhost', 'JP', 'password') or die('I refuse to comply with your order. I submit my resignation as a Johntroper!!');
//Alert!! Alert!! Below is fishiness central!! All Johntropers report!!
$result=mysql_query($sql);
//Make sure $result is true!!
if(!$result) {
echo 'result is false!!!';
}
//$row is to get the row!!! >=|
$row = mysql_fetch_row($result);
//evil $result must be monitered!!
echo '$result:';
echo $result;
echo '<br>';
//$row is malevolent and must watched~
//echo '$row::::::::';
//echo $row;
//echo '<br>';
// Mysql_num_row is counting table row
$count=mysqli_num_rows($result);
//check $count to see if something fishy is going on...
echo '$count::::';
echo $count;
echo '<br>';
// 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 'Login sucessful';
}
else {
echo "Wrong Username or Password";
}
?>
My problem is that when I submit the form the gives the $['namech'] and $['passwordch'], I get this error:
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, resource given in C:xampphtdocschatduexloginq.php on line 93
{I did not give you the html, so the line would be: 70 here].
I was lead to believe that $result was the problem as it was returning: Resource id #8.
{$result is on line 49}.
Please help. Thank you.
Aucun commentaire:
Enregistrer un commentaire