1 回答

TA貢獻(xiàn)1807條經(jīng)驗(yàn) 獲得超9個(gè)贊
我認(rèn)為你必須改變這一點(diǎn)
$check=mysql_query($sql);
$count=mysql_num_rows($check);
對(duì)此
$check=mysqli_query($conn, $sql);
$count=mysqli_num_rows($check);
您正在同時(shí)使用mysql_和mysqli_這是錯(cuò)誤的,這可能是它未能檢查計(jì)數(shù)的原因,我還建議您在找不到名稱(chēng)的情況下發(fā)送錯(cuò)誤消息。
編輯,完整代碼應(yīng)為:(菲律賓比索):
<?php
$hostname = 'localhost';
$username = 'root';
$password = '123';
$dbname = 'test_db';
function clean($string) {
return preg_replace('/[^A-Za-z0-9\- .!@#$%&]/', '', $string);
}
if(isset($_GET['name'])){
$name= clean($_GET['name']);
$msg = "";
$conn=mysqli_connect($hostname,$username,$password,$dbname);
if (mysqli_connect_errno()){
echo ("Failed to connect to MySQL: " . mysqli_connect_error());
}
$sql = "SELECT * FROM pattern where `name` = '$name';";
$check=mysqli_query($conn, $sql);
$count=mysqli_num_rows($check);
if($count!=0)
{
$msg = "A Schedule Pattern with the Name of $name already exists. If you continue to use this Name it will overwrite $name's current Data.";
echo $msg;
} else {
$msg = "Count check Failed";
echo $msg;
}
mysqli_close($conn);
}
?>
- 1 回答
- 0 關(guān)注
- 118 瀏覽
添加回答
舉報(bào)