Parse error: syntax error, unexpected $sql (T

hoping for some help here... currently i am trying to figure out what's wrong with these codes, i am stuck here for 2 days, really appreciate any kind of help. i can't seem to detect my mistake, hope for sharp eyes here.

am passing variables from android apps to php, in return the php script should return "success" or "fail"..

but i got the above error on line 6, i do not understand why. hoping someone to point out my mistake. thanks a trillion...

<?php
define('HOST','myserver.mysql');
define('USER','myserver_user');
define('PASS','myserver_pass');
define('DB','myserver_db');  

$con = mysqli_connect(HOST,USER,PASS,DB) or die('Unable to Connect');

$mobile1 = $_POST['mobile1'];
$imei1 = $_POST['imei1'];
    
$sql = "select status from phone where mobile1='$mobile1' and imei1='$imei1'";
 
$res = mysqli_query($con,$sql);
 
if(isset($check)){
    echo 'success';
}else{
    echo 'fail';
}
 
mysqli_close($con);
?>

please point out my mistake, please... thanks.

this is the line that was pointed to.

$con = mysqli_connect(HOST,USER,PASS,DB) or die('Unable to Connect');

thanks.


i managed to solve it and just want to share my answer with you guys.

hopefully this post will serves as a lesson to others as well.

what actually happened was there are "invisible" spaces between the codes, most probably when i copied from somewhere. "invisible codes" means something you get like [alt]+255 on numeric keyboard. these invisible characters was read by the php codes, thus returning the error.

the point is, ALWAYS CHECK FOR EMPTY SPACES OR UNUSED SPACES, delete all the unnecessary spaces. it might fix your (mine) problem.

thanks guys... took me 2 days... long days.

thanks stackoverflow.com

ps: hope moderator will keep this post open, as the answer might be helpful to others.


也许用这个工作?

$con = mysqli_connect("HOST","USER","PASS","DB");

// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
?>

The Problem is caused by spaces in some of the lines that you may think they are empty but it's not. remove those space characters and the error will be gone.

链接地址: http://www.djcxy.com/p/69530.html

上一篇: PHP平均计算器不能正确显示结果

下一篇: 解析错误:语法错误,意外$ sql(T