Error in your SQL syntax

Error description: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘’ at line 1
Can someone help me find this?

session_start();
//initialize variables
$Naam = "";
$Email = "";
$Pand = "";
$Huisnummer = "";
$Deel = "";
$id = 0;
// connect to database
$db = mysqli_connect("xxx","xxx","xxx","xxx");
//update records
if (isset($_POST['update'])){
    $Naam = mysqli_real_escape_string($_POST['Naam']);
    $Email = mysqli_real_escape_string($_POST['Email']);
    $Pand = mysqli_real_escape_string($_POST['Pand']);
    $Huisnummer = mysqli_real_escape_string($_POST['Huisnummer']);
    $Deel = mysqli_real_escape_string($_POST['Deel']);
    $id = mysqli_real_escape_string($_POST['id']);

    if (!mysqli_query($db, "UPDATE Info SET Naam='$Naam' , Email='$Email' , Pand='$Pand' , Huisnummer='$Huisnummer' , Deel='$Deel' WHERE id=$id")){
        echo("Error description: " . mysqli_error($db));
    }
    header('location: overzichtlocatie.php');
}
// retrieve records
$results = mysqli_query($db, "SELECT * FROM info");

Is the table name, “info” or “Info”? it makes a difference.

Info with the capital letter.

Your second query is using the lower case version. Other than that, I don’t see an issue other than the using variables in the query.

I have changed the info to Info, but still getting the same error…

if you hardcode the values in rather than using variables, does the error still trigger?

What does that mean? How can I do that?

UPDATE Info SET Naam='Alex' , Email='[email protected]' , Pand='Pand' , Huisnummer='Huisnummer' , Deel='Deel' WHERE id=1

So without the if command?

I just changed the query to show you what I meant. Everything else would stay the same

Still the same error. I will rewrite this again then… Thanks for your help!

Then i would check the column names next.

I have checked the column names, I have used the same names as in the database.

so when you put in the query into something like PHPAdmin does it also fail?

$db = new mysqli("xxx","xxx","xxx","xxx");
//update records
if (isset($_POST['update'])){
	$sql = "UPDATE Info SET Naam=?, Email=?, Pand=?, Huisnummer=?, Deel=? WHERE id=?";

    $stmt = $conn->prepare($sql);
	$stmt->bind_param("sssssi", $_POST['Naam'], 
								$_POST['Email'], 
								$_POST['Pand'], 
								$_POST['Huisnummer'], 
								$_POST['Deel'], 
								$_POST['id']);
      
    $stmt->execute();
    header('location: overzichtlocatie.php');
}

I have rewritten my code, and it works now! Thankyou for your help!

Sponsor our Newsletter | Privacy Policy | Terms of Service