1

I am trying to make a small web application with PHP and I have finally managed to get the script to pickup the first row in a table in the database and then select the next and previous rows giving the ability to cycle through all of the records while displaying each row in a form.

On one of my pages I need to collect the data from a row (Identified by a field called 'caleadID') in table(A) and then insert into another table(B). I have managed to get this data and insert into the table(B). After the data has been inserted into the table(B) it redirects me to another page and displays the data I just inserted in a form, I have a next and previous button on this page to cycle through the rows of table(B) similar to the other page. The next and previous buttons don't work as they should.

Any help would be well appreciated!

    $page = intval($_GET['page']);

    $limitStart = $page - 1;
    if($limitStart < 0) {
        $limitStart = 0;
    }

    if(isset($_GET['caleadID'])) {
        $caleadID = $_GET['caleadID'];
        $query = "SELECT caleadID, region, siteaddr1, siteaddr2, siteaddr3, siteaddr4, sitepcode, ";
        $query .= "addgennotes, description, value, award, awardaddr1, awardaddr2, awardaddr3, awardaddr4, awardpcode, ";
        $query .= "phone_number, fax_number, fldAwardedWebsite, fldAwardedEmail, contact_name, date FROM tblLeads_Awarded WHERE ";
        $query .= "caleadID = '" . $caleadID . "'";
        $query .= " LIMIT " . $limitStart . ',3';
        $result = mysqli_query($connection, $query);
        confirm_query($result);
    }
        else
    {   
        $query = "SELECT caleadID, region, siteaddr1, siteaddr2, siteaddr3, siteaddr4, sitepcode, ";
        $query .= "addgennotes, description, value, award, awardaddr1, awardaddr2, awardaddr3, awardaddr4, awardpcode, ";
        $query .= "phone_number, fax_number, fldAwardedWebsite, fldAwardedEmail, contact_name, date FROM tblLeads_Awarded WHERE 1";
        $query .= " LIMIT " . $limitStart . ',3';
        $result = mysqli_query($connection, $query);
        confirm_query($result);
    }

    $result_array = array();
    while($row = mysqli_fetch_assoc($result)) {
        $result_array[] = $row;
    }
    if(intval($page) === 0) {
        $previousRecord = NULL;
        $currentRecord = $result_array[0];
        $nextRecord = $result_array[1];
    } 
        else 
    {
        $previousRecord = $result_array[0];
        $currentRecord = $result_array[1];
        $nextRecord = $result_array[2]; 
    }
    if($previousRecord) {
        $prevPage = $page - 1;
        if($prevPage < 0) {
            $pagePage = 0;
        }
        $prevLink = 'view_leads.php?page=' . $prevPage;
    }
    if($nextRecord) {
        $nextLink = 'view_leads.php?page=' . ($page + 1);
    }
?>
<div id="tradesmen_data_navigation">
    <a href="<?PHP echo $prevLink ?>"><input type="submit" name="previous" value="Previous Record" /></a>
    <a href="<?PHP echo $nextLink ?>"><input type="submit" name="next" value="Next Record" /></a>
</div>
Jonas
  • 121,568
  • 97
  • 310
  • 388
Rubixryan
  • 107
  • 7
  • what do var_dump($prevLink) and var_dump($nextLink) look like ? Are you passing any get parameters here ? – Maximus2012 Mar 25 '14 at 19:37
  • 1
    As you said you appreceate help: If something does not work as it should, first step is to find out why. That part is missing in your "question" which is more a drop of a fairly large amount of little organized code with a call for help. No offense please, probably take a look in the Help Center on how to improve it? – hakre Mar 25 '14 at 19:38
  • @Maximus2012 That oart of the code was suggested to me in this http://stackoverflow.com/questions/22608132/how-to-cycle-through-mysql-rows/22608326?noredirect=1#comment34437131_22608326 – Rubixryan Mar 25 '14 at 20:29
  • @Rubixryan in that case you need to extend that logic to make it make use of GET which it does not do currently. – Maximus2012 Mar 25 '14 at 20:31
  • Not sure what you mean, something that I forgot to mention was that the output links for the prev and next buttons are "view_leads.php?caleadID=(THE VALUE OF THIS FROM PREVIOUS $_GET)" which I am not sure how its getting that – Rubixryan Mar 25 '14 at 20:36
  • Edited the post to give more usefull information – Rubixryan Mar 25 '14 at 20:48
  • 1
    Your code is vulnerable to SQL injections. You should read on [how to prevent them in PHP](http://stackoverflow.com/q/60174/53114). – Gumbo Mar 25 '14 at 20:51

0 Answers0