ronan23 Posted March 27, 2013 Share Posted March 27, 2013 Im having trouble with my code, whenever I press the next page (or '2') button on my website i get this error: Notice: Undefined index: board in /users/csdipact2013/rs7/public_html/blogBoard.php on line 30Notice: Undefined index: board in /users/csdipact2013/rs7/public_html/blogBoard.php on line 97 ERROR! 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 'AND m.date = ( SELECT date FROM blogmessages WHERE blogthread_id = t' at line 8 The query was: SELECT t.blogthread_id, t.subject, u.userid, t.date as date1, u.fullname, m.date FROM blogthreads as t INNER JOIN blogmessages as m INNER JOIN fanmembers as u ON t.blogthread_id = m.blogthread_id AND t.userid = u.userid WHERE t.blog_id = AND m.date = ( SELECT date FROM blogmessages WHERE blogthread_id = t.blogthread_id ORDER BY date DESC LIMIT 0,1) ORDER BY m.date DESC LIMIT 2, 2 Any help would be greatly appreciated. <?php //the title that will appear in the Windows window bar $pagetitle = 'Tyrconnell Blog: Board'; //include the standard JEdward page header //the menu button that will be highlighted, showing where the user is $thispage = 'blog'; //the standard bar of menu buttons include('donegalMenu.php'); include('donegalHeader.html'); echo '<body bgcolor="gold"> </body>'; /* ********************************************************* Main content of the page ********************************************************* */ //check that the session has been properly started by a sign-in //if so, sets the $userid variable; otherwise kills the script //NOTE: this is replacing the cookie check we did last time include_once('SessionCheck.php'); //connect to the database $dbc = mysqli_connect('cs1.ucc.ie', 'rs7', 'shainiij', 'csdipact2013_rs7') OR die('Cannot connect'. mysqli_connect_error()); $query = 'SELECT blog_name FROM blog WHERE blog_id=' . $_GET['board']; $result = mysqli_query($dbc, $query); if ($result) { $row = mysqli_fetch_array($result); echo '<p><Strong><font color="yellow" font size="5"> Tyrconnell Blog </strong></font> </p>'; echo '<p><font color="green">Blog: ' . $row['blog_name'] . '</font></p>'; if($_SESSION['userid'] == '4') // your variable equals 'yes' do something { echo '<p><a href="blogPost.php?board=' . $_GET['board'] . '"><font color="green">New Article</a></font></p>'; } } $display = 2; if (isset($_GET['pages']) && is_numeric($_GET['pages'])) { $pages = $_GET['pages']; } else //have to obtain the number from the database { $query = 'SELECT COUNT(f.blogthread_id) FROM blogthreads as f INNER JOIN blogmessages AS u ON f.blogthread_id = u.blogthread_id'; $result = @mysqli_query($dbc, $query); $row = @mysqli_fetch_array($result); $records = $row[0]; //echo '<p>I think there are ' . $records . ' records</p>'; //now work out how many pages if ($records > $display) { $pages = ceil($records/$display); } else { $pages = 1; } mysqli_free_result($result); } if (isset($_GET['start']) && is_numeric($_GET['start'])) { $start = $_GET['start']; } else { $start = 0; } $query = 'SELECT t.blogthread_id, t.subject, u.userid, t.date as date1, u.fullname, m.date FROM blogthreads as t INNER JOIN blogmessages as m INNER JOIN fanmembers as u ON t.blogthread_id = m.blogthread_id AND t.userid = u.userid WHERE t.blog_id =' . $_GET['board'] . ' AND m.date = ( SELECT date FROM blogmessages WHERE blogthread_id = t.blogthread_id ORDER BY date DESC LIMIT 0,1) ORDER BY m.date DESC LIMIT ' . $start . ', ' . $display; $result = mysqli_query($dbc, $query); //if we got a non-null result, display the table if ($result) { $number = mysqli_num_rows($result); if ($number <1) { echo '<p>Sorry - no threads have been created on this blog yet</p>'; } echo '<p><table cellpadding="3"> <tr> <td><strong><font color="green">Subject</strong></font></td> <td><strong><font color="green">Administrator</strong></font></td> <td><strong><font color="green">Start Date</strong></font></td> <td><strong><font color="green">Last Post</strong></font></td> </tr>'; //if there are any other pages of results, make links to them //we now want to display each row - we use a while since at this point we //dont know how many records we have $shade='#ffffff'; while ($row = mysqli_fetch_array($result)) { if ($shade=='#ffffff') { $shade='#eeeeee'; } else { $shade='#ffffff'; } echo '<tr bgcolor="' . $shade . '"> <td><font color="green"><a href="blogThread.php?board=' . $_GET['board'] . '&thread=' . $row['blogthread_id'] . '">' . $row['subject'] . '</a></font></td> <td><font color="green"><a href="blogUserMsg.php?userid=' . $row['userid'] . '">' . $row['fullname'] . '</a></font></td> <td><font color="green">' . $row['date1'] . '</font></td> <td><font color="green">' . $row['date'] . '</font></td> </tr>'; } echo '</table></p>'; //free up the resource used for the query mysqli_free_result($result); } else { //something went wrong echo '<p class="error">ERROR!</p>'; echo '<p>' . mysqli_error($dbc) . '</p>'; echo '<p>' . 'The query was: ' . $query . '</p>'; } //close the database mysqli_close($dbc); if ($pages > 1) { //find the current page $current_page = ($start/$display) + 1; if ($current_page != 1) { echo '<a href="blogBoard.php?start=' . ($start - $display) . '&pages=' . $pages . '">Previous</a> '; } //show a list of all numbered pages for ($i=1; $i <= $pages; $i++) { if ($i != $current_page) { echo '<a href="blogBoard.php?start=' . (($display * ($i - 1))) . '&pages=' . $pages . '">' . $i . '</a> '; } else { echo $i . ' '; } } //if the current page is not the last, then we need a nextbutton if ($current_page != $pages) { echo '<a href="blogBoard.php?start=' . ($start + $display) . '&pages=' . $pages . '">Next</a>'; } echo '</p>'; } //end if $pages > 1 /* ********************************************************* End of main content of the page ********************************************************* */ //include the standard footer information include('donegalFooter.html'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/276223-fixed-number-of-records-per-page/ Share on other sites More sharing options...
gristoi Posted March 27, 2013 Share Posted March 27, 2013 the variable: $_GET['board'] isnt being passed across in the link Quote Link to comment https://forums.phpfreaks.com/topic/276223-fixed-number-of-records-per-page/#findComment-1421430 Share on other sites More sharing options...
ronan23 Posted March 27, 2013 Author Share Posted March 27, 2013 What would I have to do to pass it? Quote Link to comment https://forums.phpfreaks.com/topic/276223-fixed-number-of-records-per-page/#findComment-1421434 Share on other sites More sharing options...
gristoi Posted March 27, 2013 Share Posted March 27, 2013 Do you not understand what a $_GET variable is? For you pagination to work the link for the next page button would need to pass the required variables accross with it, in this case 'board',http pages are stateless : http://www.mypage.com/page?board=12&somethingelse=something if you dont pass that into the page then $_GET['board'] wont be populated Quote Link to comment https://forums.phpfreaks.com/topic/276223-fixed-number-of-records-per-page/#findComment-1421445 Share on other sites More sharing options...
cyberRobot Posted March 28, 2013 Share Posted March 28, 2013 Did you post your real database credentials? If so, you should change your connection script(s) immediately. Quote Link to comment https://forums.phpfreaks.com/topic/276223-fixed-number-of-records-per-page/#findComment-1421589 Share on other sites More sharing options...
cyberRobot Posted March 28, 2013 Share Posted March 28, 2013 What would I have to do to pass it? You've passed the value in some links (see code at the end). As gristoi mentioned, you just need to do the same for your page links. Side note: data being passed through GET variables needs to be validated / sanitized. As far as I can tell, I don't see that happening in the script. Since the information isn't being cleaned, the potential for someone to inject code into your SQL query(ies)...or tamper with your page since the variables are being displayed back to the screen. echo '<p><a href="blogPost.php?board=' . $_GET['board'] . '"><font color="green">New Article</a></font></p>'; Quote Link to comment https://forums.phpfreaks.com/topic/276223-fixed-number-of-records-per-page/#findComment-1421595 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.