Myndeks Posted September 20, 2014 Share Posted September 20, 2014 Hello, $sql = "Select * from picture WHERE category = animatio' ORDER BY id DESC LIMIT $start, $max"; $for = $numRows = $conn->query("SELECT COUNT(*) FROM picture WHERE category = 'animation'")->fetchColumn(); if ($for > 0) { foreach($conn->query($sql) as $row) { print '<p>"'.$row['title'].'"</p><br><img src="'.$row['img'].'" width="651" height="215" id="img" /><br><h1><a href="'.$row['img'].'" download="'.$row['img'].'"/>Download Cover</a></h1> <hr>'; } $conn = null; when i'm deleted this: if ($for > 0) { foreach($conn->query($sql) as $row) { print '<p>"'.$row['title'].'"</p><br><img src="'.$row['img'].'" width="651" height="215" id="img" /><br><h1><a href="'.$row['img'].'" download="'.$row['img'].'"/>Download Cover</a></h1> <hr>'; } Error disappear, but code not work. And error is: Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 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 '' ORDER BY id DESC LIMIT -5, 5' at line 1' in D:\xamp\htdocs\uzdarbis\test.php:34 Stack trace: #0 D:\xamp\htdocs\uzdarbis\test.php(34): PDO->query('Select * from p...') #1 D:\xamp\htdocs\uzdarbis\test.php(41): covers() #2 {main} thrown in D:\xamp\htdocs\uzdarbis\test.php on line 3 if think what problem is here: $sql = "Select * from picture WHERE category = animatio' ORDER BY id DESC LIMIT $start, $max"; but i cant uderstand where.. :/ if i do this; $sql = $conn->prepare("Select * from picture WHERE category = animatio' ORDER BY id DESC LIMIT $start, $max"); error disapear, but code dosent work :/ Link to comment https://forums.phpfreaks.com/topic/291183-help-begginer-with-php-code/ Share on other sites More sharing options...
jcbones Posted September 20, 2014 Share Posted September 20, 2014 You have an error here: Missing a single quote in query string, fixed below $sql = "Select * from picture WHERE category = 'animatio' ORDER BY id DESC LIMIT $start, $max"; You should be binding params though. http://us1.php.net/manual/en/pdostatement.bindparam.php Link to comment https://forums.phpfreaks.com/topic/291183-help-begginer-with-php-code/#findComment-1491662 Share on other sites More sharing options...
Myndeks Posted September 21, 2014 Author Share Posted September 21, 2014 I don't understand can you help me fixed it ? Link to comment https://forums.phpfreaks.com/topic/291183-help-begginer-with-php-code/#findComment-1491695 Share on other sites More sharing options...
cyberRobot Posted September 22, 2014 Share Posted September 22, 2014 I don't understand can you help me fixed it ? Are you asking how to fix the query? If so, jcbones already provided the corrected code. You just need to add the missing quote before animatio. Change this: $sql = "Select * from picture WHERE category = animatio' ORDER BY id DESC LIMIT $start, $max"; To this: $sql = "Select * from picture WHERE category = 'animatio' ORDER BY id DESC LIMIT $start, $max"; Link to comment https://forums.phpfreaks.com/topic/291183-help-begginer-with-php-code/#findComment-1491795 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.