我正在构建一个函数,但是有一个错误请帮我解决这个问题。
错误行是这样的: -
解析错误:语法错误,第25行/home/u854338141/public_html/login/register.php中的文件意外结束
我的代码: -
<?php
//Recieve username and password from android device or GET request
$user = $_GET['username'];
$pass = $_GET['password'];
//Database connection information
$dbhost = "mysql.hostinger.in";
$dbuser = "u854338141_root";
$dbpass = "1234567";
$dbname = "u854338141_demo";
//Create a connection to databse
$con = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
//Define sql statement for you business logic: registration
$sql = "INSERT into login(username, password) VALUES('" . $user . "', '" .
$pass . "');
//Execute sql statement
$result = $con->query($sql);
if($result){
echo json_encode(array("Result"=>true));
}else{
echo json_encode(array("Result"=>false));
}
答案 0 :(得分:5)
更改
//Define sql statement for you business logic: registration
$sql = "INSERT into login(username, password) VALUES('" . $user . "', '" .
$pass . "')";
在最后一个括号后添加双引号
答案 1 :(得分:2)
$sql = "INSERT into login(username, password) VALUES('" . $user . "', '" .
$pass . "')";
您没有关闭查询。在结束括号之后的查询末尾缺少双引号"
。
答案 2 :(得分:0)
您的代码是正确的,只需在插入查询中添加双qoute,您的问题就解决了。正确的代码如下:
<?php
//Recieve username and password from android device or GET request
$user = $_GET['username'];
$pass = $_GET['password'];
//Database connection information
$dbhost = "mysql.hostinger.in";
$dbuser = "u854338141_root";
$dbpass = "1234567";
$dbname = "u854338141_demo";
//Create a connection to databse
$con = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
//Define sql statement for you business logic: registration
$sql = "INSERT into login(username, password) VALUES('" . $user . "', '" .
$pass . "')"; // This line you missed double quote ' " '
//Execute sql statement
$result = $con->query($sql);
if($result){
echo json_encode(array("Result"=>true));
}else{
echo json_encode(array("Result"=>false));
}
?>
如果您仍有问题,请告诉我们。