在添加Mysql DB(PHP)之前检查记录

时间:2018-11-28 19:04:26

标签: php mysql

添加新记录的代码运行正常,但是在这里我希望它首先检查记录是否存在,然后不要添加它,否则应该创建它。请在下面的代码中添加您的反馈代码,以帮助我...

<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");

mysql_connect('localhost', 'usrzverif23', '11254');

mysql_select_db('rification');

$fileid    = mysql_real_escape_string($_GET['fileid']);
$shopno = mysql_real_escape_string($_GET['shopno']);
$name = mysql_real_escape_string($_GET['name']);
$cnic = mysql_real_escape_string($_GET['cnic']);
$mobile = mysql_real_escape_string($_GET['mobile']);
$secretcode = mysql_real_escape_string($_GET['secretcode']);

// TODO: check that $from and $message are not empty and are valid

$sql    = "insert into usrzshopz (fileid, shopno, name, cnic, mobile, 
secretcode) values 
('$fileid','$shopno','$name','$cnic','$mobile','$secretcode')"; 
$result = mysql_query($sql);  // This actually executes the query on the 
server

if(!$result) { 
echo "Error " . mysql_error();
} else {
echo "Success";
}

?>

0 个答案:

没有答案