解析错误:语法错误,意外的“;” 在 C:\xampp\htdocs\look_api.php 第 3 行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21880996/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Parse error: syntax error, unexpected ';' in C:\xampp\htdocs\look_api.php on line 3
提问by user3328087
I got a script called look_api.php for a generator.
我有一个名为 look_api.php 的脚本用于生成器。
But when I try it I get this:
但是当我尝试时,我得到了这个:
Parse error: syntax error, unexpected ';' in C:\xampp\htdocs\look_api.php on line 3
The page:
这一页:
<?php
error_reporting(1);
$user = str_replace("'", "\\'", str_replace('"', '\"', $_GET['user']);
if($username = NULL) { $username = "Yvan" };
$con=mysqli_connect("MYSQL_IP","USER","PASSWORD","DATABASE");
// Mysql Connection
if (mysqli_connect_errno())
{
echo "Ai, check je mysql connection!: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT look FROM users WHERE username = '".$username."'");
while($row = mysqli_fetch_array($result))
{
?>
<?php
}
mysqli_close($con);
?>
</div> </div>
When I remove the ; on the line I get this error:
当我删除 ; 在线上我收到此错误:
Parse error: syntax error, unexpected T_IF in C:\xampp\htdocs\look_api.php on line 4
The code in the script is on that moment:
脚本中的代码在那一刻:
<?php
error_reporting(1);
$user = str_replace("'", "\\'", str_replace('"', '\"', $_GET['user'])
if($username = NULL) { $username = "Yvan" };
$con=mysqli_connect("MYSQL_IP","USER","PASSWORD","DATABASE");
// Mysql Connection
if (mysqli_connect_errno())
{
echo "Ai, check je mysql connection!: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT look FROM users WHERE username = '".$username."'");
while($row = mysqli_fetch_array($result))
{
?>
<?php
}
mysqli_close($con);
?>
</div> </div>
So... How do I fix it?
所以......我该如何解决它?
回答by Awlad Liton
you have missed )in here:
你)在这里错过了:
$user = str_replace("'", "\\'", str_replace('"', '\"', $_GET['user']);
should be :
应该 :
$user = str_replace("'", "\\'", str_replace('"', '\"', $_GET['user']));
you also have errors in :
您也有以下错误:
if($username = NULL) { $username = "Yvan" };
should be :
应该 :
if($username == NULL) { $username = "Yvan"; };
回答by Sumit Bijvani
Error in 3rd and 4th line
第 3 行和第 4 行错误
3rd line you missing )
4th line semicolon should be inside of ifstatement
您缺少的)
第3 行第 4 行分号应该在if语句内
Replace it..
代替它..
$user = str_replace("'", "\\'", str_replace('"', '\"', $_GET['user']));
if($username == NULL) { $username = "Yvan"; }
回答by Codrutz Codrutz
Replace
代替
if($username = NULL) { $username = "Yvan" };
With:
和:
if($username = NULL) { $username = "Yvan"; }

