我是编码和php的新手,所以我意识到这可能不是理想的编码方式,以实现我的目标。我的目标是每天允许一次提交到表格中。我设置一个等于数字的变量。然后它应该查询表以查看是否有一行具有该号码和会话的用户。如果已存在具有该编号的行,我不希望向表提交任何新信息。如果该行不存在,我希望将User和Number放在表中。
$nd = '5';
$nd = $td;
$connect = mysql_connect("a","a","a") or die ("Problem Connecting to Database");
mysql_select_db("a") or die ("Can't find database");
$query1 = mysql_query("SELECT * From p1 WHERE td='$td'");
$numrows1 = mysql_num_rows($query1);
if($numrows1 !=9999)
{
while($rows1 = mysql_fetch_assoc($query1))
{
$dbtd = $rows1['td'];
}
if ($dbtd==$td)
{
echo "You have already submitted Today.";
}
else
{
$connect = mysql_connect("a","a","a") or die ("Problem Connecting to Database");
mysql_select_db("a") or die ("Can't find database");
$query = mysql_query("INSERT INTO p1 VALUES('$name','$nd')");
die("Submission Complete <a href = 'a'>Go Home</a>");
}
}
答案 0 :(得分:0)
我建议使用唯一索引创建一个日期列(date
类型),该索引每天会强制执行一条记录。