PHP Prepared语句插入数据库

时间:2013-12-12 21:31:35

标签: php mysql

有没有人看到任何有问题的东西。它根本没有发布到数据库。有一个基本形式要求页面上的名称和地址。但在提交表单后,它只会转到空白页面。

这是我的代码。上面有一些东西可以通过API来验证地址数据并声明变量。代码的重复数据删除部分在重要的情况下工作。

if(empty($errorMessage)) 
    {
        // Dedupe the entry into the form 
        $dupesql = "SELECT * FROM formData WHERE (name = '$full_name' AND address = '$primary_number' AND city = '$city_name' AND state = '$state_abbreviation' AND zip = '$zipcode_full' )";
        $duperaw = $mysqli->query($dupesql);
        if($duperaw->num_rows > 0) {
            $dupe .= "$full_name already exists on $primary_number \n";
        } 
        else {

        $sql = "INSERT INTO formData(name, address, city, state, zip, date) VALUES (?, ?, ?, ?, ?, ?)";
        $stmt = $mysqli->prepare($sql);
        $stmt->bind_param("ssssss", $full_name, $primary_number, $city_name, $state_abbreviation, $zipcode_full, $date);
        $stmt->execute(); 

        header("location: index.php?success=1");
        exit();
        }
    }

我也尝试使用查询而不是预备语句,但这只是给出了成功消息并且没有发布到数据库

$sql = "INSERT INTO fromData (name, address, city, state, zip, date) VALUES (".
                $full_name . ", " .
                $primary_number . ", " .
                $city_name . ", " .
                $state_abbreviation . ", " .
                $zipcode_full . ", " .
                $date . ")";
$mysqli->query($sql);

任何帮助都会很棒!

1 个答案:

答案 0 :(得分:1)

试试这个SQL

 $sql = "INSERT INTO fromData (name, address, city, state, zip, date) VALUES ('$full_name', '$primary_number', '$city_name', '$state_abbreviation', '$zipcode_full', '$date')";
 $mysqli->query($sql);

cHao暗示着它