-2
這是我的代碼: 1)連接代碼 2)登錄頁面我有一個MySQL的代碼,我在面臨危機「mysqli_num_rows()預計參數1被mysqli_result,串給出」
<?php
ini_set("display_errors",1);
class connection //create a class for make connection
{
var $host = "localhost";
var $username = "root";
var $password = "";
var $database = "myDb";
var $myconn;
var $select;
var $query;
function database() //create a function for connect to database
{
$conn = mysqli_connect($this->host,$this->username,$this->password);
if(!$conn) // testing the connection
{
die ("Cannot connect to the database");
}
else
{
$this->myconn = $conn;
}
mysqli_select_db($this->myconn,$this->database); //use php inbuil function for select database
if(mysqli_error($this->myconn)) //if error occured display the error message\\
{
echo "Cannot find the database " . $this->database;
}
return $this->myconn;
}
function query($select)
{
$this->query= mysqli_query($this->myconn,$select)or die(mysqli_error($this->myconn));
}
function fetchQuery()
{
return mysqli_fetch_array($this->query);
}
function closeConnection() //close the connection
{
mysqli_close($this->myconn);
}
}
?>
和我正在處理它的頁面。
<?php
$connection = new connection();
$connection->database();
if(isset($_POST['submit']))
{
$user = $_POST['name'];
$pass = $_POST['password'];
$select = "SELECT * From tab_user where txt_uname ='$user' and txt_pass ='$pass' ";
$result = $connection->query($select);
$count = mysqli_num_rows($result);
if($count>0)
{
$row = $connection->fetchQuery();
$name = $row['txt_full_name'];
echo $name;
$connection->closeConnection();
}
else
{
echo 'Wrong Inputs.';
}
}
?>
<form method="post">
<input type="text" name="name">
<input type="password" name="password">
<input type="submit" name="submit" value="submit">
</form>
我面臨一個問題「mysqli_num_rows()期望參數1是mysqli_result,字符串給定」。 我該如何解決它。請幫忙 。謝謝 !!
仍然有問題。 –