我創造一些表(在MySQL):PHP,MySQL的輸入數據
create table clients
(clientid int unsigned not null auto_increment primary key,
Name char(50) not null,
SecondName char(50) not null,
address char(100) not null,
City char(30) not null
Email char(100);
我想輸入DATAS(名稱,SecondName,地址,城市,電子郵件)到我的數據庫NewClientBase從網頁由客戶填寫
<html>
<?php
...
// short names initialization. Taken from filling external form
$Name=$_POST['Name'];
$SecondName=$_POST['SecondName'];
$Address=$_POST['Address'];
$City=$_POST['City'];
$Email=$_POST['Email'];
$clientid=0;
if (!$Name || !$SecondName || !$Address || !$City || !$Email) {
echo "Not all data completed.<br />"
."Return and try again";
exit;
}
if (!get_magic_quotes_gpc()) {
$Name = addslashes($Name);
$SecondName = addslashes($SecondName);
$Address = addslashes($Address);
$City = addslashes($City);
$Email = doubleval($Email);
}
@ $db = new mysqli('localhost', 'root', '********', 'NewClientBase');
$wynik_sprawdzania= mysqli_query($db, $sprawdzanie);
$ile_znalezionych=$wynik_sprawdzania->fetch_row();
$ilosc_pol=$wynik_sprawdzania->field_count;
.....
// a new record with the next number is calculated:
$clientid=$wynik_sprawdzania->fetch_row()+1;
....
and created a new record with this number:
$zapytanie = "insert into clients values ('".$clientid."','".$Name."','".$SecondName."', '".$Address."','".$City."', '".$Email."')";
$wynik = $db->query($zapytanie);
.....
$db->close();
?>
</html>
的問題是::
如果(例如)產生並輸入5到記錄數據庫這樣
將所有記錄正確插入到數據庫中。
但如果它被插入這樣
$zapytanie = "insert into clients values
('".$clientid."','".$Name."','".$SecondName."', '".$Address."','".$City."', '".$Email."')";
$wynik = $db->query($zapytanie);
(如上所示$的clientid否5 programly計算)記錄不被創建。既不''.clientid。''也不'。$ clientid。'有誰能夠幫助我?有任何解決方案?謝謝
好,和如何解決? – adrian
解決方案是我上面寫的源代碼行。變量周圍的單引號使字符串插入。 Wirhout它是一個數字。 –