我不明白爲什麼它不起作用? 這是我的代碼,,在register.phpPHP表格保存到數據庫
<form action="register_save.php" method="POST">
<input style="margin-left: 60px;" type="text" name="member_firstname"/>
<input style="margin-left: 10px;" type="text" name="member_lastname" />
<input style="margin-left: 80px;" type="text" name="member_username" />
<input style="margin-left: 82px;" type="password" name="member_password" />
<input style="margin-left: 30px;" type="password" name="member_password_confirm" />
<button class="uk-button uk-button-success" type="submit">
<i class="uk-icon-share-square"></i>
</button>
</form>
在registe_save.php
<?php
ob_start();
include_once "../connect.php";
$member_firstname = $_POST["member_firstname"];
$member_lastname = $_POST["member_lastname"];
$member_username = $_POST["member_username"];
$member_password = $_POST["member_password"];
$member_password_confirm = $_POST["member_password_confirm"];
$sql = "INSERT INTO tb_member(member_firstname, member_lastname, member_username, member_password)
VALUES('$member_firstname','$member_lastname','$member_username','$member_password')"
if(mysql_query($sql) {
header("location: template.php?url=register_complete");
}
?>
當我提交,頁面將運行到register_save.php,但什麼都沒有發生,數據未保存到數據庫
爲什麼......?
**危險**:您正在使用[一個**過時的**數據庫API](http://stackoverflow.com/q/12859942/19068)並應使用[現代替換](http://php.net/manual/ EN/mysqlinfo.api.choosing.php)。你也**易受[SQL注入攻擊](http://bobby-tables.com/)**,現代的API會使[防禦]更容易(http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php)自己從。 – Quentin 2014-09-13 07:52:38
嘗試''「。$ member_firstname。」'''在所有字段中嵌入''member_firstname'' – 2014-09-13 07:54:03
@CodeBaba - 爲什麼?這隻會讓代碼更難閱讀。 – Quentin 2014-09-13 07:57:22