abcdefgin Posted May 15, 2015 Share Posted May 15, 2015 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>. Quote Link to comment https://forums.phpfreaks.com/topic/296338-error-in-simple-code-calling-from-database/ Share on other sites More sharing options...
Barand Posted May 15, 2015 Share Posted May 15, 2015 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 Quote Link to comment https://forums.phpfreaks.com/topic/296338-error-in-simple-code-calling-from-database/#findComment-1511963 Share on other sites More sharing options...
abcdefgin Posted May 15, 2015 Author Share Posted May 15, 2015 Thanks! Other issues: 1) I can't seem to figure out why the footer isn't showing up 2) All content on page continuously repeats 7x? Quote Link to comment https://forums.phpfreaks.com/topic/296338-error-in-simple-code-calling-from-database/#findComment-1511971 Share on other sites More sharing options...
CroNiX Posted May 15, 2015 Share Posted May 15, 2015 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']); / Quote Link to comment https://forums.phpfreaks.com/topic/296338-error-in-simple-code-calling-from-database/#findComment-1511986 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.