-1

I have created a webservice for registration but when i am running a webservice it gives me error:

Parse error: syntax error, unexpected 'INTO' (T_STRING) in C:\xampp\htdocs\create.php on line 13

I have added my code here

<?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);
?>
manjiri
  • 61
  • 1
  • 1
  • 6
  • 1
    I don't think those are real quotes, please change to `"` and `'`! They seem MsWord single quotes and double quotes. – Mihai Iorga Aug 22 '17 at 06:21
  • 1
    and for the love of Buddha stop using mysql_* –  Aug 22 '17 at 07:11
  • it gives error in dbconfig.php i have added code – manjiri Aug 22 '17 at 09:55
  • FYI, [you shouldn't use `mysql_*` functions in new code](http://stackoverflow.com/questions/12859942/). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [red box](http://php.net/manual/en/function.mysql-connect.php)? Learn about [*prepared statements*](https://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://php.net/manual/en/mysqlinfo.api.choosing.php) will help you decide which one is best for you. – John Conde Aug 22 '17 at 10:43
  • still it gives error – manjiri Aug 22 '17 at 14:33

1 Answers1

0

Please replace with ' and with ".

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