0

I am building a function and there is an error please help me to resolve this.

The error line is this:-

Parse error:syntax error, unexpected end of file in /home/u854338141/public_html/login/register.php on line 25

My Code:-

<?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));
}
Peter Haddad
  • 78,874
  • 25
  • 140
  • 134

3 Answers3

5

change

//Define sql statement for you business logic: registration
$sql = "INSERT into login(username, password) VALUES('" . $user . "', '" . 
$pass . "')";

add double quote after last bracket

Tigran Babajanyan
  • 1,967
  • 1
  • 22
  • 41
2
$sql = "INSERT into login(username, password) VALUES('" . $user . "', '" . 
$pass . "')";

You didn't close the query. There is a missing double quote " at the end of the query just after the closing bracket.

Fabrice Kabongo
  • 671
  • 10
  • 23
parkway
  • 276
  • 1
  • 15
  • 1
    Please don't duplicate answers , be more attentive ..... – Artsrun Hakobyan Jul 27 '17 at 06:34
  • the only query that he gave. i cannot modified the statement, or the query or the attribute from the original post. The only things that i can do is fixing the missing value, symbol or etc.. It is same when u trying to fixing a words.. Let say someone miss spelled the word airplane, he wrote airplant.. and hes asking whats wrong with the words.. even 10 people answer it, 100% sure they definitely answer AIRPLANE as their answer. And you you come over to those people who answered AIRPLANE and asking them not t duplicate since the only answer is only AIRPLANE.. – parkway Jul 27 '17 at 06:44
  • Dear @parkway It's not about this specific case, it's generally – Artsrun Hakobyan Jul 27 '17 at 06:48
  • what else did you can change in the query instead of replacing or adding a missing symbol? since the only problem that clearly – parkway Jul 27 '17 at 06:51
  • I upvoted your answer , means I agree with your answer , I'm just saying when you see someone already answers don't post same answer that's it , something remains unclear ? – Artsrun Hakobyan Jul 27 '17 at 06:54
  • i didnt mean to repeating the same things. anyway sorry. – parkway Jul 27 '17 at 06:56
  • Everything is ok , anyway thank you too for your efforts – Artsrun Hakobyan Jul 27 '17 at 06:58
0

You code is right just add double qoute in the Insert query and your problem solved. Right code is as follows :

<?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));
}

?>

If still you have issue please let us know.

Prabhu Nandan Kumar
  • 1,205
  • 12
  • 22