I have 4 text boxes named offerId, AffId,status and deduction which is fetching data from the database and displaying say 5 rows. There is an "update entry" button with each row of the form, so that if a user edits the data of a text box and hits the update button, it updates the 'status' & 'deduction' against that offerId and AffId.
The problem I'm facing is my script which updates the data picks up the values of offerId and AffId of the last row (being displayed in the form), and updates the status and deduction against it. How do I use the entered value against which the button is pressed, and update it in the database?
The script of my form, and the script which updates my form to the database looks like this:
<?php
include('adodb/adodb.inc.php');
echo '<h1>Mxpresso Revenue Management Solution</h1>';
echo '<img src="http://mxpresso.com/images/logo.png" alt="mxpresso logo" style="width:171px;height:108px;">';
echo '<h2>1. To See existing records</h2>';
$db=NewADOConnection('mysql');$db->Connect("127.0.0.1", "vcc", "abc", "vcc");
$sql="select * from rev";
$result = $db->Execute($sql);
if ($result === false) die("failed2");
$records=array();
$count=$result->RecordCount();
echo "Total Records Found :".$count."<br>";
echo '<form action="rev_insert.php" >
<input type="submit" value="Add Entry">
</form>';
if($count > 0) {
for ($x=0;$x<$count;$x++) {
$offerId=$result->fields[0];
$affId=$result->fields[1];
$status=$result->fields[2];
$deduction=$result->fields[3];
echo '<form target="_blank" action="updatecopy.php" method="get">
<table id="dataTable" class="form" border="1">
<tbody><tr>
<p>
<td><input type="checkbox" required="required" name="chk[]" checked="checked"></td>
<td>
<h4>OfferID</h4>
<input type="text" name="offerId" value='.$offerId.' >
</td>
<td>
<h4>ffId</h4>
<input type="text" name="affId" value='.$affId.' >
</td>
<td>
<h4>deduction:</h4>
<input type="text" name="deduct" value='.$deduction.' >
</td>
<td>
<h4>Status</h4>
<input type="text" name="status" value='.$status.' >
</select>
</td>
</p>
</tr>
</tbody>
</table>
<input type="submit" value="Update Entry">';
$rec=array("offerId"=>$offerId,"affiliate_id"=>$affId,"status"=>$status, "deduction"=>$deduction);
array_push($records,$rec);
$result->MoveNext();
}
}
?>
The script which updates:
<?php
include('adodb/adodb.inc.php');
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else
{
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
$url=curPageURL();
$str = parse_url($url, PHP_URL_QUERY );
parse_str($str);
$db=NewADOConnection('mysql');
//$db->debug = true;
echo "created DB connection";
$db->Connect("127.0.0.1", "vcc", "abc", "vcc");
$sql="update rev set deduction=".$deduct.", status=".$status." where offerId='".$offerId."' and affId='".$affId."';";
echo "SQL Query:".$sql;
$result = $db->Execute($sql);
if ($result === false) die("Failed to Update. Check if OfferId and AffID are correct");
?>
