1

This page generates a table that contains all the data on the billing_reports table in my database. When you double click on an item, you can enter in a new value in the field, then press enter to save. The problem is that when I press submit, it just refreshes the page, without updating the changes to the database. How do I fix this?

<?php
        include_once ("includes/config.php");
        include_once ("includes/functions.php");
        include_once ("includes/header.php");
    ?>
    <!--How this works, is that this page generates a table that containes all 
        the data on the billing_reports table in my database. When you double 
        click on an item, you can enter in a new value in the field, then press
        enter to save. The problem I am having, is that when I press submit it 
        just refreshes the page, when I want it to update the changes to the database. 
        How do I fix this? -->  
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
    <script type="text/javascript" src="script.js"></script>
    <?php
     // $data = All the rows in billing reports
     $data = mysql_query("SELECT * FROM billing_reports") 
     or die(mysql_error());

     // This is printing the Javascript table listed above
    ?> <table class="editableTable"> <?php
     Print "<editableTable border cellpadding=4>"; 

    //This is defining $info as the action that seperates the $data pulled from the database
     while($info = mysql_fetch_array( $data )) 
    { 
     Print "<tr>"; 
     Print "<th>Name:</th> <td>".$info['cc_name'] . "</td> ";
     Print "<th>ID:</th> <td>".$info['br_id'] . "</td> ";
     Print "<th>Listing ID:</th> <td>".$info['listing_id'] . "</td> ";
     Print "<th>Payment:</th> <td>".$info['billing_amount'] . "</td> ";
     Print "<th>Status:</th> <td>".$info['status'] . " </td></tr>"; 
     } 
     Print "</table>";

    if (!$_POST['submit']) {
        $result = mysql_query($info);
        $person = mysql_fetch_array($result);
    }

    if(isset($_POST['submit'])) {
        $info = "UPDATE billing_reports SET cc_name='$_POST[cc_name]', br_id='$_POST[br_id]', listing_id='$_POST[listing_id]', billing_amount='$_POST[billing_amount]', status='$_POST[status]'"; 
        mysql_query($info) or die(mysql_error());

        echo"Agent has been modified!";

    }
    ?>

    <form action="" method="post" class="button">
        <li>Save Changes</br>
        <input type="submit" <name="submit" value="Modify"/></li>
    </form>

    <?php
    include_once ("includes/footer.php"); 
    ?>
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

2 Answers2

3

You have a misstaping in your input which is making the input itself not workig, isset() for submit will never be true

<input type="submit" <name="submit" value="Modify"/></li>
                   //^ here you don't need <

As side not i would advise that you are highly vulnerable to mysql injections, i would rather switch either to pdo or mysqli and use prepared statements

Community
  • 1
  • 1
Fabio
  • 23,183
  • 12
  • 55
  • 64
  • Thanks, I made the changes but no such luck I'm afraid. I still can't actually do any editing to the database from the page, it still just resets everything when submit. – user3361851 Feb 27 '14 at 20:18
  • As for the isset(), what would you suggest I use instead? – user3361851 Feb 27 '14 at 20:19
1

There's a typo in this line, < before name:

  <input type="submit" <name="submit" value="Modify"/></li>

And using an editor with code highlighting is usually recommended.

Reger
  • 474
  • 4
  • 17