如何解决Parse错误:语法错误,意外' $ _ POST' (T_VARIABLE)

时间:2016-06-17 08:31:22

标签: php mysqli

请,我该如何解决这个问题。我最初使用的mysql与我有问题。现在我开始学习mysqli了。我现在不了解所有细节,但我需要让这个脚本工作和安全。目前我有这个:

  

解析错误:语法错误,意外' $ _ POST' (T_VARIABLE)in   第27行的C:\ xampp \ htdocs \ yomi \ admin \ update.php

查询:

CREATE TABLE IF NOT EXISTS `news` (
  `id` int(10) NOT NULL,
  `title` varchar(225) NOT NULL,
  `brief` varchar(500) NOT NULL,
  `contents` varchar(2000) NOT NULL,
  `author` varchar(2000) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

PHP:

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "my_db";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// prepare and bind
$stmt = $mysqli->prepare("UPDATE news SET title = ?,
   brief = ?,
   contents = ?, 
   author = ? 
   WHERE id = 1");

// set parameters and execute
$stmt->bind_param("ssssi", $_POST['title'],
$_POST['brief'],
$_POST['contents'],
$_POST['author'],
$_POST['id']);
$stmt->execute();
echo "New records updated successfully";
$conn->close();
?> 

2 个答案:

答案 0 :(得分:1)

你在$ _POST [&#39;作者&#39;]

之后错过了一个逗号
$stmt->bind_param("ssssi", $_POST['title'],
    $_POST['brief'],
    $_POST['contents'],
    $_POST['author'],
    $_POST['id']);
    $stmt->execute();
    echo "New records updated successfully";
    $conn->close();
    ?> 

答案 1 :(得分:0)

您在绑定参数的$_POST['author']后缺少逗号。