advancedfuture Posted March 21, 2007 Share Posted March 21, 2007 Alright I got my Pagination to work on my page. But when I try to narrow my rows down to a certain parameter rather than pulling all rows, i get. These are the lines with the errors. You can statements work, and which ones dont. The statements that pull all rows works and I dont get an error. Fatal error: FATAL ERROR in C:\apache\htdocs\index.php on line 49 If i edit line 32 so it says (works): $query = "SELECT count(*) FROM upload"; rather than (doesnt): $query = "SELECT count(*) FROM upload where category = '$category'"; and line 48 so it says (works): $query = "SELECT * FROM upload $limit"; rather than(doesnt): $query = "SELECT * FROM upload WHERE category = '$category' $limit"; Yet what I find interesting is the queries that generate an error work no problem if i type them into mySQL query browser... So alas I am a bit lost as to why this is giving me an SQL error. Finally: Full Source <!-- FORM TO DISPLAY DATABASE TEMPLATES --> <form name="form1" method="post" action="<?php echo $PHP_SELF?>"> <select name="section" size="1" multiple> <option selected>layouts</option> </select> <select name="category" size="1"> <option selected>animals</option> <option>Anime</option> </select> <br> <input type="submit" name="Submit" value="Submit"> </form> <!-- END DISPLAY FORM --> <? //GET FORM DATA $section = $_POST['section']; $category = $_POST['category']; if (isset($_GET['pageno'])) { $pageno = $_GET['pageno']; } else { $pageno = 1; } // if require("connectDB.php"); //DATABASE CONNECTION SEQUENCE $query = "SELECT count(*) FROM upload WHERE category = '$category'"; $result = mysql_query($query) or trigger_error("FATAL ERROR", E_USER_ERROR); $query_data = mysql_fetch_row($result); $numrows = $query_data[0]; $rows_per_page = 1; $lastpage = ceil($numrows/$rows_per_page); $pageno = (int)$pageno; if ($pageno < 1) { $pageno = 1; } elseif ($pageno > $lastpage) { $pageno = $lastpage; } // if $limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page; $query = "SELECT * FROM upload $limit"; $result = mysql_query($query) or trigger_error("FATAL ERROR", E_USER_ERROR); if ($pageno == 1) { echo " FIRST PREV "; } else { echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a> "; $prevpage = $pageno-1; echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a> "; } // if echo " ( Page $pageno of $lastpage ) "; if ($pageno == $lastpage) { echo " NEXT LAST "; } else { $nextpage = $pageno+1; echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT</a> "; echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>LAST</a> "; } // if //FETCH SQL DATA AND PRINT IT TO THE SCREEN while($row = mysql_fetch_array($result)){ $id = $row["id"]; $codes = $row["codes"]; // $codes = ereg_replace("INSERTURLHERE", , $codes); NOT CURRENTLY USING THIS FEATURE print '<table width="400" border="2" cellspacing="0" cellpadding="0">'; //DISPLAY THUMBNAIL IMAGE FROM DATABASE print ("<tr><td><img src=\"download.php?id=$id\"></td></tr>"); //POPULATE TEXTFIELD WITH CSS CODE FOR TEMPLATE print "<tr><td><textarea name='textfield' wrap='OFF' cols='50' rows='7'>".$codes."</textarea></td></tr>"; print '</table><br /><br />'; } require("disconnectDB.php"); ?> Link to comment https://forums.phpfreaks.com/topic/43608-solved-fatal-error-line-49-sql-query/ Share on other sites More sharing options...
mmarif4u Posted March 21, 2007 Share Posted March 21, 2007 Try this: <!-- FORM TO DISPLAY DATABASE TEMPLATES --> <form name="form1" method="post" action="<?php echo $PHP_SELF?>"> <select name="section" size="1" multiple> <option selected>layouts</option> </select> <select name="category" size="1"> <option selected>animals</option> <option>Anime</option> </select> <br> <input type="submit" name="Submit" value="Submit"> </form> <!-- END DISPLAY FORM --> <?php require("connectDB.php"); //DATABASE CONNECTION SEQUENCE //GET FORM DATA $section = $_POST['section']; $category = $_POST['category']; if (isset($_GET['pageno'])) { $pageno = $_GET['pageno']; } else { $pageno = 1; } // if $rows_per_page = 1; $lastpage = ceil($numrows/$rows_per_page); $pageno = (int)$pageno; if ($pageno < 1) { $pageno = 1; } elseif ($pageno > $lastpage) { $pageno = $lastpage; } // if $limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page; $query = "SELECT count(*) FROM upload WHERE category = '$category'"; $result = mysql_query($query) or trigger_error("FATAL ERROR", E_USER_ERROR); $query_data = mysql_fetch_row($result); $numrows = $query_data[0]; $query = "SELECT * FROM upload $limit"; $result = mysql_query($query) or trigger_error("FATAL ERROR", E_USER_ERROR); //FETCH SQL DATA AND PRINT IT TO THE SCREEN while($row = mysql_fetch_array($result)){ $id = $row["id"]; $codes = $row["codes"]; // $codes = ereg_replace("INSERTURLHERE", , $codes); NOT CURRENTLY USING THIS FEATURE print '<table width="400" border="2" cellspacing="0" cellpadding="0">'; //DISPLAY THUMBNAIL IMAGE FROM DATABASE print ("<tr><td><img src=\"download.php?id=$id\"></td></tr>"); //POPULATE TEXTFIELD WITH CSS CODE FOR TEMPLATE print "<tr><td><textarea name='textfield' wrap='OFF' cols='50' rows='7'>".$codes."</textarea></td></tr>"; print '</table><br /><br />'; } if ($pageno == 1) { echo " FIRST PREV "; } else { echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a> "; $prevpage = $pageno-1; echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a> "; } // if echo " ( Page $pageno of $lastpage ) "; if ($pageno == $lastpage) { echo " NEXT LAST "; } else { $nextpage = $pageno+1; echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT</a> "; echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>LAST</a> "; } // if require("disconnectDB.php"); ?> Link to comment https://forums.phpfreaks.com/topic/43608-solved-fatal-error-line-49-sql-query/#findComment-211768 Share on other sites More sharing options...
advancedfuture Posted March 21, 2007 Author Share Posted March 21, 2007 unfortunately I get the same error regarding the line: $result = mysql_query($query) or trigger_error("FATAL ERROR", E_USER_ERROR); seems whenever I specify "WHERE category = '$category'" in my code it breaks, Just does not want to let me query only a certain value in the database. Link to comment https://forums.phpfreaks.com/topic/43608-solved-fatal-error-line-49-sql-query/#findComment-211795 Share on other sites More sharing options...
mmarif4u Posted March 21, 2007 Share Posted March 21, 2007 change this: $limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page; $query = "SELECT count(*) FROM upload WHERE category = '$category'"; $result = mysql_query($query) or trigger_error("FATAL ERROR", E_USER_ERROR); $query_data = mysql_fetch_row($result); $numrows = $query_data[0]; $query = "SELECT * FROM upload $limit"; $result = mysql_query($query) or trigger_error("FATAL ERROR", E_USER_ERROR); To this: $limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page; $query = "SELECT count(*) FROM upload WHERE category = '$category'"; $result = mysql_query($query) or trigger_error("FATAL ERROR", E_USER_ERROR); $query_data = mysql_fetch_row($result); $numrows = $query_data[0]; $query = "SELECT * FROM upload WHERE category = '$category' $limit"; $result = mysql_query($query) or trigger_error("FATAL ERROR", E_USER_ERROR); If this does not work do it like this: $limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page; $query = "SELECT count(*) FROM upload WHERE category = '$category' $limit"; $result = mysql_query($query) or trigger_error("FATAL ERROR", E_USER_ERROR); $query_data = mysql_fetch_row($result); $numrows = $query_data[0]; $query = "SELECT * FROM upload WHERE category = '$category' "; $result = mysql_query($query) or trigger_error("FATAL ERROR", E_USER_ERROR); Link to comment https://forums.phpfreaks.com/topic/43608-solved-fatal-error-line-49-sql-query/#findComment-211801 Share on other sites More sharing options...
advancedfuture Posted March 21, 2007 Author Share Posted March 21, 2007 Yeah I had originally tried those 2 options you just said before I made this post. LoL In part why I am stuck and perplexed. I fail to see why its generating the error. ******************* by using the first option you stated it generates an error on the next line: $result = mysql_query($query) or trigger_error("FATAL ERROR", E_USER_ERROR); On the second option you recommended when I tried that it too generetes an error on the next line $result = mysql_query($query) or trigger_error("FATAL ERROR", E_USER_ERROR); Link to comment https://forums.phpfreaks.com/topic/43608-solved-fatal-error-line-49-sql-query/#findComment-211806 Share on other sites More sharing options...
advancedfuture Posted March 21, 2007 Author Share Posted March 21, 2007 solved my problem, If i change the first query to: $query = "SELECT count(*) FROM upload WHERE category = '" . mysql_real_escape_string($category) . "'"; Link to comment https://forums.phpfreaks.com/topic/43608-solved-fatal-error-line-49-sql-query/#findComment-211825 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.