-1

Getting an error PHP Parse error: syntax error, unexpected end of file in C:\Inetpub\vhosts\mysite.com\subdomains\login\public\helpdesk\deleteproduct.php on line 41

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

?>
  • 1
    if you'd take the time to properly indent your code, you'll undoubtedly find the `}` that's missing in your code (or whatever punctuation is missing, if it's not a `}`. – Marc B Jul 21 '16 at 16:56
  • "The mechanical turk just doesn't fulfill me like it used to." – George Cummins Jul 21 '16 at 16:58

1 Answers1

0

Add ending brace:

if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}
fislerdata
  • 290
  • 1
  • 4
  • 8
  • ok now I get this error PHP Fatal error: Call to a member function prepare() on null in C:\Inetpub\vhosts\mysite.com\subdomains\login\public\helpdesk\deleteproduct.php on line 21 – Ed Meredith Jul 21 '16 at 16:59
  • @EdMeredith, that's another question. If this answer was helpful, you should accept it (clicking on its checkmark), then you post another question (about this new fatal error). – Jose Manuel Abarca Rodríguez Jul 21 '16 at 17:00
  • Early in the script you use `$conn` for your connection but then you switch to `$mysqli`. Changing `$mysqli` to `$conn` should take care of it. – fislerdata Jul 21 '16 at 17:52