我在這個網站上瀏覽過很多不同的代碼。找出我的代碼有什麼問題。基本上我只想在表格中搜索並測試結果。我寫的是這樣的:MySQL select沒有選擇
<?php
ob_start();
session_start();
$conn = new mysqli('localhost','username','password','mytable');
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$valuetotest = 'something';
$result = mysql_query("SELECT id FROM members WHERE UserName = $valuetotest");
if(mysql_num_rows($result) == 0)
{
echo "User not found";
}
$password = 'something2';
$userData = mysql_fetch_array($result, MYSQL_ASSOC);
if($password != $userData['Password'])
{
echo "Password not found";
}else{ // Redirect to home page after successful login.
header('Location: welcome.php');
}
?>
我總是得到消息:
"User not found." and "password not found."
當我知道用戶名和密碼都在表...
無我」 m對PHP/MySQL非常熟悉,所以在我面前可能會有一些相當大的東西,我看不到它!
有人可以幫忙。感謝名單。
好了mysqli的......但我想$ valuetotest是一個變量不是一個常量...... – NorKayak
是即使如此,你必須使用'用戶名='$ valueetotest'',但是抱歉,我不會在我的答案中提出一些建議,以後可能會對代碼造成傷害。請繼續準備好的聲明並查看我添加到我的答案中的鏈接。 –
好的,現在好了... – NorKayak