[英]php with mysql, the code is not inserting into my table
大修改:
新腳本:
<?php
error_reporting(E_ALL|E_NOTICE);
$nazwabazydanych = "projekt";
$pesel = mysql_real_escape_string($_POST['pesel']);
$imie = mysql_real_escape_string($_POST['imie']);
$nazwisko = mysql_real_escape_string($_POST['nazwisko']);
$telefon = mysql_real_escape_string($_POST['telefon']);
$adres = mysql_real_escape_string($_POST['adres']);
$nr_konta = mysql_real_escape_string($_POST['nr_konta']);
$zarobek = mysql_real_escape_string($_POST['zarobek']);
if (!$pesel || !$imie || !$nazwisko || !$telefon || !$adres || !$nr_konta || !$zarobek)
{
print "Nie zostały wypełnione wszystkie pola";
exit;
}
$db = mysql_pconnect("localhost", "root", "");
if (!$db)
{
print "Nie można nawiązać połączenia z bazą danych";
exit;
}
mysql_select_db("$nazwabazydanych");
$query = mysql_query("CALL dodaj_osobe ('$pesel','$imie','$nazwisko','$telefon','$adres','$nr_konta','$zarobek')");
?>
行動:
<form action="lool.php" method="post">
PESEL: <input type="text" name="pesel" maxlength=11 size=12><br><br>
Imię: <input type="text" name="imie" maxlength=45 size=46><br><br>
Nazwisko: <input type="text" name="nazwisko" maxlength=45 size=46><br><br>
Telefon: <input type="text" name="telefon" maxlength=9 size=10><br><br>
Adres: <input type="text" name="adres" maxlength=45 size=46><br><br>
Numer konta: <input type="text" name="nr_konta" maxlength=20 size=21><br><br>
Zarobek: <input type="text" name="zarobek" maxlength=8 size=9><br><br>
<input type="submit" value="Dodaj klienta">
</form>
和更新的錯誤:
沒有!
謝謝大家,但是我有一個問題:如果“ nr_konta”或“ pesel”或“ telefon”位數太低,如何發送錯誤?
您需要使用$ _POST數組獲取POST變量,除非已啟用register_globals
。
$pesel = mysql_real_escape_string($_POST['pesel']);
$imie = mysql_real_escape_string($_POST['imie']);
$nazwisko = mysql_real_escape_string($_POST['nazwisko']);
$telefon = mysql_real_escape_string($_POST['telefon']);
$adres = mysql_real_escape_string($_POST['adres']);
$nr_konta = mysql_real_escape_string($_POST['nr_konta']);
$zarobek = mysql_real_escape_string($_POST['zarobek']);
// Put this after so you don't have to restate the $_POST vars
if (!$pesel || !$imie || !$nazwisko || !$telefon || !$adres || !$nr_konta || !$zarobek)
{
print "Nie zostały wypełnione wszystkie pola";
exit;
}
使用print_r($_POST)
您應該查看是否獲得值。 在您的代碼中,問題似乎是您沒有使用正確的索引。 注意Pesel沒有通知,但是imie有。
您的兩個代碼:
$pesel = mysql_real_escape_string($_POST['pesel']);
$imie = mysql_real_escape_string($_POST['$imie']);
請注意,您將'$imie'
作為索引。 我猜這里復制和粘貼錯誤。 從html看來,該元素名為imie。 嘗試這個:
$imie = mysql_real_escape_string($_POST['imie']);
您實際上並沒有獲得$ _POST值。
應該
$pesel = mysql_real_escape_string($_POST['pesel']);
$imie = mysql_real_escape_string($_POST['imie']);
$nazwisko = mysql_real_escape_string($_POST['nazwisko']);
$telefon = mysql_real_escape_string($_POST['telefon']);
$adres = mysql_real_escape_string($_POST['adres']);
$nr_konta = mysql_real_escape_string($_POST['nr_konta']);
$zarobek = mysql_real_escape_string($_POST['zarobek']);
那些應該在你之前
if (!$pesel || !$imie || !$nazwisko || !$telefon || !$adres || !$nr_konta || !$zarobek)
另外,您需要從$_POST
值中刪除$
。
$_POST['$imie']
應該:
$_POST['imie']
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.