我有一个脚本可以将记录保存到mysql,没有任何问题。但我想添加一些代码来显示错误消息,如果数据库中已存在名称或代码。代码如下所示;
<?php
$urunadi = $_POST["urunadi"];
$malzemekodu = $_POST["malzemekodu"];
$urunkategorisi = $_POST["urunkategorisi"];
$birim = $_POST["birim"];
$miktar = $_POST["miktar"];
$personel = $_POST["personel"];
$birimfiyat = $_POST["birimfiyat"];
$toplamfiyat = $_POST["birimfiyat"]*$_POST["miktar"];
$fiyatbirimi = $_POST["fiyatbirimi"];
if(empty($urunadi)){
echo("<center><b>Product name empty, please go back and fill this line.</b></center>");
}else
if(empty($miktar)){
echo("<center><b>Product amount empty, please go back and fill this line.
}else
if(empty($malzemekodu)){
echo("<center><b>Product code empty, please go back and fill this line.</b></center>");
}else
if(empty($birimfiyat)){
echo("<center><b>Unit price empty, please go back and fill this line.</b></center>");
}else{
include "database.php";
$sql = (" insert into `depo` (`urunadi`,`malzemekodu`,`urunkategorisi`,`birim`,`miktar`,`personel`,`birimfiyat`,`toplamfiyat`,`fiyatbirimi`)
VALUES ('$urunadi','$malzemekodu','$urunkategorisi','$birim','$miktar','$personel','$birimfiyat','$toplamfiyat','$fiyatbirimi');");
$kayit = mysql_query($sql);
}
if (isset ($kayit)){
echo "<center>Data saved</center>";
}
else {
echo "<center>Data could not be saved</center>";
}
if (isset($_REQUEST["kullanici"])) {
include("database.php");
$sql = ("select * from uye");
}
else {
header ("Location: uyari.html");
}
?>