Php表单保存到数据库

时间:2014-09-13 07:51:16

标签: php mysql

我不明白为什么它不起作用??? 这是我的代码,在register.php中

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

?>

当我提交时,Page将运行到register_save.php,但没有任何反应,数据也没有保存到数据库

为什么......?

3 个答案:

答案 0 :(得分:1)

if(mysql_query($sql) {

你有无与伦比的括号。

;开始的行尾,您也会丢失$sql =

这两个错误都应该在您的错误日志文件中报告。你应该看看它。

答案 1 :(得分: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");
        }

?>

答案 2 :(得分: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)) {