Jump to content


Photo

submitting to 2 tables from one form


  • Please log in to reply
2 replies to this topic

#1 xtiancjs

xtiancjs
  • Members
  • PipPipPip
  • Advanced Member
  • 47 posts

Posted 31 March 2006 - 06:14 PM

Hi all, I have a form which updates values in a dB table, is it possible from the same form to also insert a value into a different table? I just want to log the form users ip address with $_server['REMOTE_ADDR']; and use that ip later to limit form submission
Here is my form code:

form method="post" name="form2" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right"><select name="broker_rating_two" onClick="DoSubmission2();">
<?php
do {
?>
<option value="<?php echo $row_valueset2['value']?>" <?php if (!(strcmp($row_valueset2['value'], $row_bprofile['broker_rating_two']))) {echo "SELECTED";} ?>><?php echo $row_valueset2['value']?></option>
<?php
} while ($row_valueset2 = mysql_fetch_assoc($valueset2));
?>
</select></td>
<td></td>
<tr>
</table>
<input type="hidden" name="id" value="<?php echo $row_bprofile['id']; ?>">
<input type="hidden" name="broker_num_votes_two" value="<?php echo $row_bprofile['broker_num_votes_two']; ?>">
<input type="hidden" name="MM_update" value="form2">
<input type="hidden" name="id" value="<?php echo $row_bprofile['id']; ?>">
</form>

HERE IS MY FORM ACTION CODE:

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE brokers SET broker_rating= broker_rating + %s, broker_num_votes=%s + 1 WHERE id=%s",
GetSQLValueString($_POST['broker_rating'], "int"),
GetSQLValueString($_POST['broker_num_votes'], "int"),
GetSQLValueString($_POST['id'], "int"));

mysql_select_db($database_broker, $broker);
$Result1 = mysql_query($updateSQL, $broker) or die(mysql_error());
}

APOLS FOR ALL THE CODE
Xtian

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 31 March 2006 - 07:03 PM

Yes you can you just have to make another query to the database after your other query. I believe this is your query:
$updateSQL = sprintf("UPDATE brokers SET broker_rating= broker_rating + %s, broker_num_votes=%s + 1 WHERE id=%s",
GetSQLValueString($_POST['broker_rating'], "int"),
GetSQLValueString($_POST['broker_num_votes'], "int"),
GetSQLValueString($_POST['id'], "int"));

mysql_select_db($database_broker, $broker);
$Result1 = mysql_query($updateSQL, $broker) or die(mysql_error());
After GetSQLValueString($_POST['id'], "int")); do your secound query to log the users IP address.

#3 xtiancjs

xtiancjs
  • Members
  • PipPipPip
  • Advanced Member
  • 47 posts

Posted 01 April 2006 - 05:52 PM

[!--quoteo(post=360445:date=Mar 31 2006, 02:03 PM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Mar 31 2006, 02:03 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Yes you can you just have to make another query to the database after your other query. I believe this is your query:
$updateSQL = sprintf("UPDATE brokers SET broker_rating= broker_rating + %s, broker_num_votes=%s + 1 WHERE id=%s",
GetSQLValueString($_POST['broker_rating'], "int"),
GetSQLValueString($_POST['broker_num_votes'], "int"),
GetSQLValueString($_POST['id'], "int"));

mysql_select_db($database_broker, $broker);
$Result1 = mysql_query($updateSQL, $broker) or die(mysql_error());
After GetSQLValueString($_POST['id'], "int")); do your secound query to log the users IP address.
[/quote]

Thanks for the reply, that is a big help as I wasn't sure where to start my next query from, will give it a shot thanks again
xtian




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users