hi. for some reason I can get this to work. I’m not a php/sql guru.
Please can someone help?
The way I did this, is obviously a very long way, and wrong way…Have a look at my code. I’ve got 3 different queries on one page. and 3 different submit buttons to run them. I would like ONE submit button and hopefully ONE query to update the fields.
at the moment, when I update for example the first one, it updates on the DB, but the amount showing in the field, returns to the old amount.
Hope this is clear. Please help :ponder:
<?php
$db_connect = mysql_connect("server", "db", "un");
//Pick the database to use
mysql_select_db("db_name", $db_connect);
$sql1 = "Select * from markets WHERE id = 1";
$rsmarkets1 = mysql_query($sql1,$db_connect);
$rows1 = mysql_fetch_assoc($rsmarkets1);
$sql2 = "Select * from markets WHERE id = 2";
$rsmarkets2 = mysql_query($sql2,$db_connect);
$rows2 = mysql_fetch_assoc($rsmarkets2);
$sql3 = "Select * from markets WHERE id = 3";
$rsmarkets3 = mysql_query($sql3,$db_connect);
$rows3 = mysql_fetch_assoc($rsmarkets3);
?>
<?php
if (isset($_REQUEST['btnupdate1'])) {
$amount = $_REQUEST["amount1"];
$update = "Update markets set amount =" . $amount . " where id = 1";
$execute = mysql_query($update,$db_connect);
}
if (isset($_REQUEST['btnupdate2'])) {
$amount = $_REQUEST["amount2"];
$update = "Update markets set amount =" . $amount . " where id = 2";
$execute = mysql_query($update,$db_connect);
}
if (isset($_REQUEST['btnupdate3'])) {
$amount = $_REQUEST["amount3"];
$update = "Update markets set amount =" . $amount . " where id = 3";
$execute = mysql_query($update,$db_connect);
}
?>
<form name="form1" method="post" action="<?php $_SERVER['PHP_SELF'];?>?id=1">
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td align="left" width="50%"><?php echo $rows1['name'];?></td>
<td align="left" width="30%"><input name="amount1" type="text" id="amount1" value="<?php echo $rows1['amount'];?>"></td>
<td align="right" width="20%">
<input type="submit" name="btnupdate1" value="" id="submit" class="update_form_submit">
</td>
</tr>
</table>
</form>
<form name="form2" method="post" action="<?php $_SERVER['PHP_SELF'];?>?id=2">
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td align="left" width="50%"><?php echo $rows2['name'];?></td>
<td align="left" width="30%"><input name="amount2" type="text" id="amount1" value="<?php echo $rows2['amount'];?>"></td>
<td align="right" width="20%">
<input type="submit" name="btnupdate2" value="" id="submit" class="update_form_submit">
</td>
</tr>
</table>
</form>
<form name="form3" method="post" action="<?php $_SERVER['PHP_SELF'];?>?id=3">
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td align="left" width="50%"><?php echo $rows3['name'];?></td>
<td align="left" width="30%"><input name="amount3" type="text" id="amount3" value="<?php echo $rows3['amount'];?>"></td>
<td align="right" width="20%" valign="middle">
<input type="submit" name="btnupdate3" value="" id="submit" class="update_form_submit">
</td>
</tr>
</table>
</form>
<?php
mysql_free_result($rsmarkets1);
mysql_free_result($rsmarkets2);
mysql_free_result($rsmarkets3);
mysql_close($db_connect);
?>