I display records from one table. On every rows I add 2 columns (type of listbox). They are filled from another tables. How can I save choiced values from listboxes after Save? 

<!-- Anesteziolog -->
<form name="myForm" action="cos_den.php" method="post">
<?php
echo"<td >";
$cpquery = "Select anesteziolog from anesteziolog order by anesteziolog";
$cpresult = mysql_query($cpquery) or die(mysql_error());
?>

<select name="anesteziolog" value="anesteziolog">
<!-- Drop down -->
<?php
if($cpresult)
{
while($row = mysql_fetch_array($cpresult))
{
echo '<option value="' .$row['anesteziolog']. '">'. $row['anesteziolog'].</option>';
}
}
echo "<option value='anesteziolog' ></option>";
echo "</select>";

echo "</td>";
// End: Anesteziolog


//Typ anesteziologie
echo"<td >";
$cpquery = "Select anest_typ from anest_typ order by anest_typ";
$cpresult = mysql_query($cpquery) or die(mysql_error());
?>

<select name="anest_typ" value="anest_typ">
<!-- Drop down -->
<?php
if($cpresult) 
{
while($row = mysql_fetch_array($cpresult))
{
echo '<option value="' .$row['anest_typ'].'">'. $row['anest_typ']. '</option>'  ;
}
}
echo "<option value='anest_typ' ></option>";
echo "</select>";

echo "</td>";
// End: Typ anesteziologie

echo "</tr>";

}
echo "</table>";
?>
<p class="submit"><input type="submit" value="Save" name="submit"  ></>
</form>

Recommended Answers

All 6 Replies

So, are you asking how you can save the state of the form elements after the page refreshes?
Or, are you asking how you can update a table in the database when the form element has been changed?

Well, I am asking about update table with value from listboxes. Apologize my english.Thanks.

If you are familiar with jQuery (or javascript) you could submit the form with an onchange event for the form elements. That would be the easiest way that I can think of to do it. Keep in mind though, this will cause the page to reload as soon as I changed the value for any of these.

There are ways of course to get around that as well, using AJAX to submit the data to another script that updates the database table would be one.

I don't know Ajax/jQuery. I have never make with this. It's time to start. Now I need to do it quickly. Is it possible to do with ph?

It isn't possible with PHP because it has no way to know that the form element had been changed.

A simple example in jQuery that I use is:

$(function() {
      $('#elementid').change(function() {
            $('#myForm').submit();
      });
});

Here is a link to the jQuery documentation with more information on using submit()

http://api.jquery.com/submit/

jQuery is a lot simpler to use than raw javascript.

Many thanks. By.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.