Jump to content

Recommended Posts

I'm really new to PHP and have been stuck on this problem for awhile. I've been trying to insert a header, multiple images in a list, and footer from a database with this code:

 

 

-------------------------------------------------

<!DOCTYPE html> 
<html lang="en">
<meta charset="UTF-8">
 
 
<head> <title> Reimagined Movie Posters </title> </head> 
 
 
<body> 
 
 
<?php include_once "header.php"; ?>
 
 
<?php
 
include_once "db_connect.php";
 
die($mysqli->stat());
 
$result = $mysqli->query("SELECT * FROM store WHERE id=".$_GET['name']); /
 
if($mysqli->errno) die($mysqli->error);
 
while($row = $result->fetch_object()){
 
$images = explode(",", $row->images);
?>
 
 
<?php
 
}
 
?>
 
<?php include_once "footer.php"; ?>
 
</body> 
 
</html>
-------------------------------------------------
and I keep on getting the error:
 
"hello You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1"
 
What am I doing wrong? All I have on line 1 is <!doctype html>.

You need to check that data has been sent and that $_GET['name'] actually has a value before you try to use it

if (isset($_GET['name'])) {
    // process
}

Use prepared statements instead of putting user provided values into your queries

Do you have error reporting turned on and display_errors? I see a problem in your code which should be obvious, and you should be getting an error complaining about this line:

$result = $mysqli->query("SELECT * FROM store WHERE id=".$_GET['name']); /

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.