2014-09-13 159 views
-1

我不明白爲什麼它不起作用? 這是我的代碼,,在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,但什麼都沒有發生,數據未保存到數據庫

爲什麼......?

+0

**危險**:您正在使用[一個**過時的**數據庫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

+0

嘗試''「。$ member_firstname。」'''在所有字段中嵌入''member_firstname'' – 2014-09-13 07:54:03

+0

@CodeBaba - 爲什麼?這隻會讓代碼更難閱讀。 – Quentin 2014-09-13 07:57:22

回答

1
if(mysql_query($sql) { 

您有無與倫比的括號。

您還有一個從行末$sql =缺失;

這兩個錯誤都應該在錯誤日誌文件中報告。你應該看看它。

0

試試這個:

<?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"); 
     } 

?> 
+1

分號丟失 – mwafi 2014-09-13 08:01:05

+0

分號丟失在哪裏? – Quentin 2014-09-13 08:01:25

+1

聲明$ sql var後 – mwafi 2014-09-13 08:02:37

0

你錯過;

取代

$sql = "INSERT INTO tb_member(member_firstname, member_lastname, member_username, member_password) VALUES('$member_firstname','$member_lastname','$member_username','$member_password')" 

$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) { 

if(mysql_query($sql)) {