输入记录时Web服务出错

时间:2017-08-22 06:19:46

标签: php mysql web-services post

我已经创建了一个用于注册的web服务,但是当我运行web服务时,它给了我错误:

  

解析错误:语法错误,意外的'INTO'(T_STRING)   第13行的C:\ xampp \ htdocs \ create.php

我在这里添加了我的代码

<?php
/* include db.config.php */
include_once(‘db_config.php’);

if($_SERVER[‘REQUEST_METHOD’] == “POST”){
// Get post data`
$firstName = isset($_POST[‘firstname’]) ? mysql_real_escape_string($_POST[‘firstname’]) : “”;
$lastName = isset($_POST[‘lastname’]) ? mysql_real_escape_string($_POST[‘lastname’]) : “”;
$email = isset($_POST[’email’]) ? mysql_real_escape_string($_POST[’email’]) : “”;
$password = isset($_POST[‘password’]) ? mysql_real_escape_string($_POST[‘password’]) : “”;
 // Here we set by default status In-active.
// Save data into database
$query = “INSERT INTO users (firstname,lastname,email,password) VALUES (‘$firstName’,’$lastName’,’$email’,’$password’)”;
$insert = mysql_query($query);

if($insert){
$data = array(“result” => 1, “message” => “Successfully user added!”);
} else {
$data = array(“result” => 0, “message” => “Error!”);
}
} else {
$data = array(“result” => 0, “message” => “Request method is wrong!”);
}

mysql_close($conn);
/* JSON Response */
header(‘Content-type: application/json’);
echo json_encode($data);

DB_CONFIG.PHP

<?php
$db_host = 'localhost'; //hostname
$db_user = 'root'; // username
$db_password = "; 
$db_name = 'test'; 
$conn = mysql_connect($db_host, $db_user, $db_password );
mysql_select_db($db_name, $conn);
?>

1 个答案:

答案 0 :(得分:0)

请将替换为',将替换为“。

$query = "INSERT INTO users (firstname,lastname,email,password) VALUES ('$firstName','$lastName','$email','$password')";