PHP分析错误:语法错误,第41行C:\Inetpub\vhosts中的文件意外结束

PHP分析错误:语法错误,第41行C:\Inetpub\vhosts中的文件意外结束,php,Php,获取错误PHP解析错误:语法错误,在第41行的C:\Inetpub\vhosts\mysite.com\subdomains\login\public\helpdesk\deleteproduct.PHP中出现意外的文件结尾 <?php // connect to the database $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "database"; $co

获取错误PHP解析错误:语法错误,在第41行的C:\Inetpub\vhosts\mysite.com\subdomains\login\public\helpdesk\deleteproduct.PHP中出现意外的文件结尾

<?php

// connect to the database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);


// confirm that the 'id' variable has been set
if (isset($_GET['id']) && is_numeric($_GET['id']))
{
// get the 'id' variable from the URL
$id = $_GET['id'];

// delete record from database
if ($stmt = $mysqli->prepare("DELETE FROM product WHERE id = ? LIMIT 1"))
{
$stmt->bind_param("i",$id);
$stmt->execute();
$stmt->close();
}
else
{
echo "ERROR: could not prepare SQL statement.";
}
$mysqli->close();

// redirect user after delete is successful
header("location:javascript://history.go(-2)");
}
else
// if the 'id' variable isn't set, redirect the user
{
header("location:javascript://history.go(-1)");
}

?>
添加结束大括号:

if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

如果你花时间对代码进行适当的缩进,你无疑会发现代码中缺少的
}
(或者缺少任何标点符号,如果不是
}
“机械土耳其人已经不像以前那样满足我了。”好吧,现在我发现这个错误PHP致命错误:调用成员函数prepare()在C:\Inetpub\vhosts\mysite.com\subdomains\login\public\helpdesk\deleteproduct.php联机中为空21@EdMeredith,这是另一个问题。如果这个答案有帮助,你应该接受它(单击它的复选标记),然后你发布另一个问题(关于这个新的致命错误)。在脚本的早期,您使用
$conn
进行连接,但随后切换到
$mysqli
。将
$mysqli
更改为
$conn
应该会解决这个问题。