-1
我已經設置了這個簡單的表單,允許您輸入個人信息並將它們存儲在數據庫中,但它不起作用。在PHP中使用PHP存儲簡單數據
HTML表單:
<html>
<body>
<form name="test" action="store.php" method="post">
Voornaam: <input type="text" name="first_name"> <br>
Achternaam: <input type="text" name="last_name"> <br>
E-Mail: <input type="text" name="e-mail"> <br>
Telefoon: <input type="text" name="phone"> <br>
Adres: <input type="text" name="address"> <br>
Postcode: <input type="text" name="postal_code"> <br>
Stad: <input type="text" name="city"> <br>
Provincie: <input type="text" name="province"> <br>
Land: <input type="text" name="country"> <br>
<input type="submit" value="Verzenden">
</form>
<body>
</html>
而且PHP:
<?php
/*Database test.
© 2013 Sydcul. All rights reserved.*/
//Please change the following settings:
/*Your database host*/ $host = "localhost";
/*Your database user*/ $user = "root";
/*Your database password*/ $password = "";
//Please don't change the following:
$connection = mysql_connect($host, $user, $password);
mysql_select_db("contact", $connection);
$debug = "INSERT INTO data (first_name, last_name, e-mail, phone, address, postal_code, city, province, country)
VALUES ('" . $_POST["first_name"] . "', '" . $_POST["last_name"] . "', '" . $_POST["e-mail"] . "', '" . $_POST["phone"] . "', '" . $_POST["address"] . "', '" . $_POST["postal_code"] . "', '" . $_POST["city"] . "', '" . $_POST["province"] . "', '" . $_POST["country"] . "')";
mysql_query("INSERT INTO data (first_name, last_name, e-mail, phone, address, postal_code, city, province, country)
VALUES ('" . $_POST["first_name"] . "', '" . $_POST["last_name"] . "', '" . $_POST["e-mail"] . "', '" . $_POST["phone"] . "', '" . $_POST["address"] . "', '" . $_POST["postal_code"] . "', '" . $_POST["city"] . "', '" . $_POST["province"] . "', '" . $_POST["country"] . "')");
echo $debug;
mysql_close($connection);
?>
我相信我得到它的工作一次,但這是僅在第一個名字。 我認爲這是非常明顯的我看不到,所以請花點時間看看它,並幫助我。
我把調試的東西,在調試,它表明我:
INSERT INTO data (first_name, last_name, e-mail, phone, address, postal_code, city, province, country) VALUES ('John', 'Johnson', 'j[email protected]', '1234567890', 'Street 1', '1234 AB', 'City', 'Province', 'Country')
[**請不要在新代碼中使用'mysql_ *'函數**](http://bit.ly/phpmsql)。他們不再被維護[並被正式棄用](https://wiki.php.net/rfc/mysql_deprecation)。看到[**紅框**](http://j.mp/Te9zIL)?學習[*準備的語句*](http://j.mp/T9hLWi),並使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [這篇文章](http://j.mp/QEx8IB)將幫助你決定哪個。如果你選擇PDO,[這裏是一個很好的教程](http://j.mp/PoWehJ)。 –
當調試MySQL時,總是看看'mysql_query'是否失敗,以及是否給出錯誤。 '$ q = mysql_query('...'); if(!$ q){die(mysql_error()); }'http://php.net/manual/en/function.mysql-error.php –
感謝您通知我已棄用的事實。我不喜歡使用舊代碼。 – Sydcul