<?php
date_default_timezone_set('Asia/Manila');
$conn=mysql_connect("localhost","root","");
mysql_select_db("dbposo",$conn);
if(isset($_POST['add']))
{
if(empty($_POST['fname']) || empty($_POST['mname']) || empty($_POST['lname']))
{
echo "<script>alert('Please fill up all the fields!')</script>";
header("Refresh: 0;url=admin_publicviolation.php");
}
else
{
$number=$_POST['number'];
$fname=$_POST['fname'];
$mname=$_POST['mname'];
$lname=$_POST['lname'];
$age=$_POST['age'];
$gender=$_POST['gender'];
$violation=$_POST['violation'];
$officer=$_POST['officer'];
$offenses=$_POST['offenses'];
$date=date("y-m-d");
$time=date("H:i:s");
$price=$_POST['price'];
mysql_query("insert into tblcitizen(number,fname,mname,lname,age,gender,violation,officer,offenses,date,time, price) values('$number','$fname','$mname', '$lname', '$age', '$gender', '$violation' , '$officer', '$offenses','$date','$time','100')",$conn) or die(mysql_error());
echo "<script>alert('Successfully Recorded, First penalty: 100php!')</script>";
header("Refresh: 0;url=admin_publicviolation.php");
}
}
?>
我要拒絕登記,如果$數量已經存在於數據庫中,有人幫助我嗎?無法弄清楚。我不能使用一些編碼方法。不知道如何使用其他檢查數行的MySQL數據庫已經存在
先使用SELECT查詢,然後從數據庫中選擇$ number。如果存在數字,則不要插入數據,否則使用插入查詢。 – Madurai
開放SQL注入。 – Prix
嘗試這個 - 'http:// stackoverflow.com/questions/20048028 /不檢查,如果用戶被帶走/ 20048087#20048087' –