0

in my db have 20+ columns. i added 19 columns throught input form and stored in db succesfully. i fetch few details from db in my main page. in my main page 1 more column is there. that is status column, it is a combo box. if i click status column it should show 4 values. i want to select that values and click save button it must go to stored in db with that same ID. how to do that?
mainpage combo box coding:

echo "\t<td width=148><form action=statusdb.php method=post>
    <select name=update><option value=empty></option><option value=Confirm>Confirm</option><option value=Processing>Processing</option><option value=Pending>Pending</option><option value=Cancelled>Cancelled</option></select>
    <input name=\"update[".$a_row['slno']."]\"; type=submit value=Save></form>
    </td>\n";

status db code:

if (isset($_POST['update']))
{ 
$update = mysql_real_escape_string(trim($_POST['update']));
$sql = mysql_query("UPDATE guestdetails SET status = $update WHERE ($slno) = '$slno'");
if(!mysql_query($sql, $connect))
{
    die("Error:" .mysql_error());
}
}

if anyone knows help me..

2
Contributors
1
Reply
23
Views
4 Years
Discussion Span
Last Post by hag++
0

Well in order to do that update you are going to need to know which record ID is currently in context. There are a couple of ways to do this but the easiest way for you would be to put a hidden input field in the form that contains the ID. Then in your PHP script just grab that ID and make the update.

This is a very simplified explanation not sutied for production code since it doesn't check that the user has access to update the record (if applicable) but it gets the idea across. I updated your example HTML code below.

echo "\t<td width=148><form action=statusdb.php method=post>
    <select name=update><option value=empty></option><option value=Confirm>Confirm</option><option value=Processing>Processing</option><option value=Pending>Pending</option><option value=Cancelled>Cancelled</option></select>
    <input name=\"update[".$a_row['slno']."]\"; type=submit value=Save>
    <input name=\"record_id\"; type=\"hidden\" value=\"[".$a_row['slno']\">
</form>

</td>\n";

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.