PHP Insert Into函数只工作一次?

时间:2014-03-30 13:51:40

标签: php mysql database

我试图编写一些PHP代码,将通过表单提交的数据添加到我创建的数据库表中。它很棒 - 一次。一旦我提交了数据并通过表单将其添加到数据库中,它将不再有效。我认为使用var_dump()时我写的函数存在问题。对于我在表格中提交的变量,他们都很好。

我很感激你们的任何建议,谢谢!

<form action="" method="post">

            <label for="habbo_name"><center><b>Habbo Name:</b></label><br >               
            <input type="text" name="habbo_name" size="30">

            <b><center>Transfer Status:<br ><select name="transfer_status">
                <option value="Stage Five">Stage Four - Rejected</option>
                <option value="Stage Four">Stage Four - Accepted</option>
                <option value="Stage Three">Stage Three</option>
                <option value="Stage Two">Stage Two</option>
                <option value="Stage One" selected="selected">Stage One</option>
            </select>

            <label for="date"><center><b>Date:</b></label><br >
            <input type="text" name="date" size="30"><br />

            <input type="Submit"><br /><br />

    </form>

    <a href="modtransfers.php">Go back</a>

    <?php     
    if (empty($_POST) === false) {
            $habbo_name = $_POST['habbo_name'];
            $transfer_status = $_POST['transfer_status'];
            $date = $_POST['date'];

            add_transfer($habbo_name, $transfer_status, $date);
            header('Location: moderate.php');
            exit();
    }
    ?>

功能:

function add_transfer($habbo_name, $transfer_status, $date) {
    global $con;
    $query = "INSERT INTO `transfers` SET `habbo_name`='$habbo_name', `transfer_status`='$transfer_status', `date`='$date'";
    $update = $con->prepare($query);
    $update->execute();
}

1 个答案:

答案 0 :(得分:-1)

插入查询中存在语法错误,请按以下方式使用

$query = "INSERT INTO `transfers` (`habbo_name`,`transfer_status`,`date`) VALUES ('$habbo_name', '$transfer_status', '$date')";