Php 检查数据库中的重复条目
首先,您需要根据输入选择记录:- 从表中选择时间,其中时间=您的输入时间 然后计算从查询结果中得到的行数Php 检查数据库中的重复条目,php,Php,首先,您需要根据输入选择记录:- 从表中选择时间,其中时间=您的输入时间 然后计算从查询结果中得到的行数 <?php if (isset($_POST["submit"])) { $error = ""; if (!empty($_POST["time"])) { $time = $_POST["time"]; } else { $error .= "You didn't type in a time. <b
<?php
if (isset($_POST["submit"])) {
$error = "";
if (!empty($_POST["time"])) {
$time = $_POST["time"];
}
else {
$error .= "You didn't type in a time. <br />";
}
if (empty($error)) {
$success = header("Location: index.php");
$sql = "INSERT INTO appointment(time) VALUES('".$time."')";
$query = mysql_query($sql) or die(mysql_error());
}
}
?>
<?php
if (!empty($error)) {
echo '<p class="error">' . $error . '</p>';
} else if (!empty($success)) {
echo $success;
}
?>
我想这可能会帮助你:
if(count_rows > 0) {
// then go back for input again
}
else {
// insert row.
}
$query=“从您的表中选择时间,其中时间=”“$time.”;
mysql\u查询($query);
if(mysql\u num\u rows()>0){
$error.=“已占用时间。
”;
}
到目前为止你做了什么?我想我应该在if(!empty($\u POST[“time”]){//检查副本的条件中有一个if语句,但我不知道该写什么。谢谢。它起作用了。:)很高兴帮助:),祝你好运
$query = "select time from yourtable where time='".$time ."'";
mysql_query($query);
if(mysql_num_rows()>0){
$error .= "Time already been taken. <br />";
}