运行脚本时出现解析错误
解析错误:语法错误,意外'' (T_ENCAPSED_AND_WHITESPACE),期望C:\ Program Files(x86)................. \ get.php中的标识符(T_STRING)或变量(T_VARIABLE)或数字(T_NUM_STRING)第24行
我看不出什么是错的,有人可以帮我吗?
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "database;
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname) ;
// Check connection
if ($conn->connect_error)
{
die('Connection failed: ' . $conn->connect_error) ;
}
else
{
$product1 = filter_input(INPUT_POST, 'id', FILTER_SANITIZE_NUMBER_INT) ;
$query = 'SELECT price FROM forms WHERE name=' . $product1 . ' ' ;
$res = mysql_query($query) ;
if (mysql_num_rows($res) > 0)
{
$result = mysql_fecth_assoc($res) ;
echo json_encode($result['price']);
}
else
{
echo json_encode('no results') ;
}
}
?>
答案 0 :(得分:3)
除了$dbname = "database;
中缺少引号外,您的代码中还有很多错误。
你在这里混合使用MySQL API。 mysql_
不会与mysqli_
API混用。
因此,您需要将mysql_
的所有实例更改为mysqli_
,并在查询中传递连接参数。
然后,mysql_fecth_assoc
被错误拼写并使用添加的i
进行了更正。
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "database";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname) ;
// Check connection
if ($conn->connect_error)
{
die('Connection failed: ' . $conn->connect_error) ;
}
else
{
$product1 = filter_input(INPUT_POST, 'id', FILTER_SANITIZE_NUMBER_INT) ;
$query = 'SELECT price FROM forms WHERE name=' . $product1 . ' ' ;
$res = mysqli_query($conn, $query) ;
if (mysqli_num_rows($res) > 0)
{
$result = mysqli_fetch_assoc($res) ;
echo json_encode($result['price']);
}
else
{
echo json_encode('no results') ;
}
}
还检查错误:
答案 1 :(得分:1)
更改
override func viewDidLoad() {
super.viewDidLoad()
flashButton(button1, imageName: "code1") { (finished) -> Void in
self.flashButton(self.button1, imageName: "code2")
}
}
}
到
$dbname = "database;
答案 2 :(得分:1)
您在此行中遗漏了"
:
$dbname = "database;
应该是:
$dbname = "database";
希望这有帮助,谢谢!