【问题标题】:T_OBJECT_OPERATOR while trying to insert data into mySQL data [closed]尝试将数据插入 mySQL 数据时的 T_OBJECT_OPERATOR [关闭]
【发布时间】:2013-08-15 11:57:20
【问题描述】:

试图将代码输入到 sqldatabase...我在这里缺少什么? 解析错误:语法错误,意外的 T_OBJECT_OPERATOR

<?php
$name = "";
$email = "";
$msg_to_user = "";
if ($_POST['name'] != "") {

    require_once("storescripts/connect_to_mysqli.php");

    // Be sure to filter this data to deter SQL injection, filter before querying database
    $name = $_POST['name'];
    $email = $_POST['email'];
    $sqlCommand = "SELECT * FROM newsletter WHERE email='$email'";
    $sql = mysqli_query($myConnection,$sqlCommand);
    $numRows = mysqli_num_rows($sql);
        if (!$email) {

        $msg_to_user = '<br /><br /><h4><font color="FF0000">Please type an email address ' . $name . '.</font></h4>';
    } else if ($numRows > 0) {
        $msg_to_user = '<br /><br /><h4><font color="FF0000">' . $email . ' is already in the system.</font></h4>';

    } else {
        $sqlCommand="INSERT INTO newsletter (name, email, dateTime)                                                     VALUES(?,?,NOW() )";
$stmt= $myConnection->prepare($sqlCommand);
$stmt=->bind_param('ss',$name,$email);
$stmt->execute();
    $msg_to_user = '<br /><br /><h4><font color="0066FF">Thanks ' . $name . ', you have been added successfully.</font></h4>';
        $name = "";
        $email = "";
    }
}
?>

【问题讨论】:

    标签: php mysql database sql-insert


    【解决方案1】:

    你有这个代码:

    $stmt=->bind_param('ss',$name,$email);
    

    应该是这样的:

    $stmt->bind_param('ss',$name,$email);
    

    进一步(不相关的)建议:

    【讨论】:

    • 谢谢,总是想念一些小事...累的工作要尝试一整天的代码>。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多