0

So I got this form which lets the user enter up to 10 item IDs and then check for the status or apply changes right away. If the user clicks check status the item IDs will be sent to another PHP.

What is the easiest way to send the result back to the form and display it in the red area?

enter image description here

if ($_POST['action'] == 'Check Status/Shelf') {
    $itemids = "$itemID1, $itemID2, $itemID3, $itemID4, $itemID5, $itemID6, $itemID7, $itemID8, $itemID9, $itemID10";
    while ($row = mysql_fetch_array($all)) {
        $hyllplacering = $row['Hyllplacering'] . "";
        $all = mysql_query("SELECT Hyllplacering, itemID FROM booking WHERE itemID IN ('$itemids')");
    }
}
MarcoS
  • 17,323
  • 24
  • 96
  • 174
Snoken
  • 103
  • 1
  • 11
  • to be honest, i think ajax still the best way of doing this – onegun Jan 21 '15 at 10:28
  • 7
    Your queries are unsafe! You're using the ***deprecated*** `mysql` extension ([read **the red box** at the top](http://www.php.net/mysql_connect) - it says _warning_ for a reason). Learn about injection attacks, and how to prevent them. Use either one of the modern extensions (`PDO` or `mysqli`): they support prepared statements and are fairly easy to use. [here's an example](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php). These issues need to be fixed before you do anything else! – Elias Van Ootegem Jan 21 '15 at 10:29
  • The easiest way is to.. just... echo it? Yeah, I think it is. AJAX would be more user-friendly, but not that easy. – Forien Jan 21 '15 at 10:33
  • @Forien: You consider generating the form a second time, with the values filled in easier than an AJAX call that injects some markup in a div _easier_? – Elias Van Ootegem Jan 21 '15 at 11:03
  • @EliasVanOotegem yes it is easier. Not better, not more efficient, not user friendly and not faster. But easier. For developer. Especially for someone who needs to ask question like that here on SO. – Forien Jan 21 '15 at 14:53

2 Answers2

0

If you don't want to use Ajax, then save the details into a $_SESSION[] and upon submission the form is posted and then the details can be populated into SESSION and displayed back out to the form upon reloading, but it's a bit of a fiddle for not much return.

And use MySqli or PDO.

Martin
  • 22,212
  • 11
  • 70
  • 132
0

For that you have to use ajax

Give id to Apply Changes & Check Status/Self button

<script type="text/javascript">
$(document).ready(function(){
     $('#apply').click(function() {
         var id1 = $('#id1').val();
         var id2 = $('#id2').val();
        //same for all your 10 field
         var cstring = "id1="+id1+"&id2="+id2 // etc;
            $.ajax({
                  type: "POST",
                  url: "your file url to do database opration & fetch detail back to here",
                  data: cstring,
                  cache: false,
                  success: function(result) {
                      $('.resultdata').html(result)
                  }
            });
     });
});
</script>

<div class="resultdata"></div>
jay.jivani
  • 1,560
  • 1
  • 16
  • 33