mysql tamsayı sorun

3 Cevap

i mysql veritabanına veri eklemek için aşağıdaki kodu kullanıyorum

<?php
$debdes  = $_POST['debdes'];
$debamt  = $_POST['debamt'];
$crdes   = $_POST['crdes'];
$cramt   = $_POST['cramt'];
$date    = $_POST['date'];
$cberror = "<h1>Data not Added</h1><br/><br/><h3>Please Follow The Instructions</h3>";

include_once ("db.php");



if (empty ($date)) die ("$cberror");

if (empty ($debamt) && empty ($debdes) && empty ($cramt) && empty ($cramt)) die ("$cberror");

if (!empty($debamt) && empty ($debdes))die ("$cberror");

if (!empty($debdes) && empty ($debamt)) die ("$cberror");


if (!empty($cramt) && empty ($crdes)) die ("$cberror");

if (!empty($crdes) && empty ($cramt)) die ("$cberror");

 $ucbook = "INSERT INTO cbook(debdes,debamt,crdes,cramt,date) VALUES ('$debdes','$debamt','$crdes','$cramt','$date');";

if(mysql_query("$ucbook"))

{
echo "<h3>One Record Updated Successfully with the following Details </h3><br/>";
echo "Date = $date <br/><br/>";
echo "Debt Amount =$debamt <br/><br/>";
echo "Debt Description = $debdes <br/><br/>";
echo "Credit Amount = $cramt <br/><br/>";
echo "Credit Description = $crdes <br/><br/>";

}
else 
{
echo "<be/><br/>The Following Error Occure While Updatig Data<br/><br/>";
echo mysql_error(); 
}

?>

Şimdi sorun i mysql de tamsayı olarak "debamt" değerini ayarlamak gibi o hata geliyor olması

Incorrect integer value: '' for column 'debamt' at row 1 

i "debamt" değer eklemek vermedi, ancak ben de doğru diğer verileri dolduruyorum

???

3 Cevap

Bu debamt boş olduğu anlamına gelir. Boş doğru bir tamsayı değeri değil.

Biliyorsun, sen de ameliyathaneyi anlamına || mantıksal operatörü kullanabilirsiniz. Bu satır Çünkü:

if (empty ($debamt) && empty ($debdes) && empty ($cramt) && empty ($cramt)) die ("$cberror");

... Bu değerlerin birinin bile boş değil ise, fıkra patlamaz eğer anlamına gelir. Ne muhtemelen istiyorum:

if (empty ($debamt) || empty ($debdes) || empty ($cramt) || empty ($cramt)) die ("$cberror");

Alanlardan biri boş ise bu şekilde, komut devam etmeyecektir. Bu da sonuçta çek bir sürü işe yaramaz hale getirir.

Çünkü mevcut kod, bu $debamt boş olarak aracılığıyla alır bu tamamen mümkündür. Ben eğer hükümler düşünmek sizi engourage ve gerçekten gerekli ne görmek istiyorum.

Kodundan o $debamt boş olması için hala mümkün gibi görünüyor, böylece sql deyimi boş bir argüman eklemek için çalışıyor. '' Geçerli bir tamsayı değil

Boş bir dize geçerli bir tamsayı değil. Eğer boş değerlere izin sütunu beyan etmelidir size uygun bir dizi sağlar (ve oldukça boş bir dize daha boş geçmesi) gerekir ya.

Ayrıca okumalısınız SQL injection.