I am having difficulty implementing an ajax example from the W3C website. The example pulls back results from a database and displays them in a table based on which option has been selected from a Dropdown menu.
http://www.w3schools.com/php/php_ajax_database.asp
I have tried configuring this example to meet my requirements. This is to update a field in the database based on the option that is selected. I think i'm close I just wanted to make sure I am on the right track. When an option is selected an ajax call is made which triggers my php script to make the changes. It looks like this:
<?php
$q = mysql_real_escape_string($_POST['q']);
print_r($_GET["q"]);
$con = mysql_connect('localhost', '', '');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("Orders", $con);
$sql= "UPDATE Orders SET status='.$_POST[q]['.$i.'].' WHERE ID='.$_POST[order_no] ['.$i.'].'";
however this data is not entered into the database. I can retrieve the value of $q which is either 'approved' 'pending' or 'disapproved' but not the specific order number to update that individual row. My select box looks like this:
echo '<select name="order_status[]" id="id" onchange="showUser(this.value)">';
echo '<option value = "Pending" name="order_status['.$i.']" class = "pending"' . ($row['status'] == 'Pending' ? ' selected=selected' : '') . '>Pending</option>';
echo '<option value = "Approved" name="order_status['.$i.']" class = "approved"' . ($row['status'] == 'Approved' ? ' selected=selected' : '') . '>Approved</option>';
echo '<option value = "Disapproved" name="order_status['.$i.']" class ="disapproved"' . ($row['status'] == 'Disapproved' ? ' selected=selected' : '') . '>Disapproved</option>';
this is wrapped in form which also sends an email based on which checkbox is selected. This functionality works and I can send an email to an individual row:
<form method ="post" action="sendemail.php">
echo '<td><input type="checkbox" name="order_selected['.$i.']"/></td>';
//in send mail.php:
if(isset($_POST['order_selected']))
{
$keys = array_keys($_POST['order_selected']);
foreach($keys as $key)
//send email
do I need to implement the update code in the same php script? or use the same approach to loop through an array?
Many Thanks