1 回答

TA贡献1807条经验 获得超9个赞
我认为你必须改变这一点
$check=mysql_query($sql);
$count=mysql_num_rows($check);
对此
$check=mysqli_query($conn, $sql);
$count=mysqli_num_rows($check);
您正在同时使用mysql_和mysqli_这是错误的,这可能是它未能检查计数的原因,我还建议您在找不到名称的情况下发送错误消息。
编辑,完整代码应为:(菲律宾比索):
<?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 关注
- 73 浏览
添加回答
举报