这是我在试验 PHP 我是新手。我正在尝试查看是否已在 mysql 数据库中找到给定的用户名,这是我当前的代码:
<?php
// $uname is the username I am trying to see if is the database
$uname = "djm";
//server info
$servuser = "root";
$servpass = "";
$db = "toob";
$server = "127.0.0.1";
//connecting to server
$db_handle = mysql_connect($server, $servuser, $servpass);
$db_found = mysql_select_db("toob", $db_handle);
//checking to see if ocnnected
if ($db_found) {
print("connected");
//defining my sql statement
$sql = "SELECT username FROM users WHERE username = $uname";
$result = mysql_query($sql);
if ($result) {
print("Yes");
} else {
print("No");
}
} else {
print("Can't connect to server");
}
我总是打印不,我设法通过替换来打印是:
$sql="SELECT username FROM users WHERE username = $uname";
$result=mysql_query($sql);
和
$sql="SELECT username FROM users WHERE username = 'djm'";
$result=mysql_query($sql);
但是我需要是否处理变量。