How to edit and delete the selected row
Moderator: General Moderators
Re: How to edit and delete the selected row
Can you please post the latest versions of supplies.php and suppliesEdit.php.
Re: How to edit and delete the selected row
Hi there, sir Stryks. Thanks for your response. Below is the php code for supplies.php
and here is the suppliesEdit.php
and here is the form code for the suppliesEdit.php
And here is the code for suppliesUpdate.php
thank you once again.
Code: Select all
<?php
$query = "SELECT supplies_PK, code, name, quantity, measurement, perUnitCost, totalCost FROM $tbl_name";
$result = mysql_query($query) or die('Error in Query');
echo "<table width=\"720\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"gridData\" >";
while($row = mysql_fetch_assoc($result)){
$get_id=$row['supplies_PK'];
echo "<tr onMouseOver=\"this.style.backgroundColor='#EDE6D4'\"; onMouseOut=\"this.style.backgroundColor='transparent'\">";
echo "<td width = \"60\" >".$row['code']."</td>";
echo "<td width = \"140\">".$row['name']."</br></td>";
echo "<td width = \"78\" align = \"right\">".$row['quantity']." </br></td>";
echo "<td width = \"112\"> ".$row['measurement']."</br></td>";
echo "<td width = \"116\" align = \"right\">".$row['perUnitCost']."</br></td>";
echo "<td width = \"89\" align = \"right\">".$row['totalCost']."</br></td>";
//edit and delete added here
echo "<td width = \"90\" align = \"center\"><a href=\"suppliesEdit.php?entry_id=$get_id\"> Edit </a> | <a href=\"suppliesDelete.php?entry_id=$get_id\"> Delete </a>";
echo "</tr>";
}
echo "</table>";
// close connection
mysql_close();?>Code: Select all
<?php
//start session
session_start();
//include mysql_connection.php to connect to the database
require_once("connectSupplies.php");
if(!isset($_SESSION['user'])){
header("location:index.php");
}
$entry_id = $_GET['entry_id'];
$sql = "SELECT supplies_PK, code, name, quantity, measurement, perUnitCost, totalCost FROM tbl_supplies WHERE supplies_PK = $entry_id";
$result = mysql_query($sql) or die (mysql_error());
$row = mysql_fetch_assoc($result);
$did = $row['supplies_PK'];
$dcode = $row['code'];
$dname = $row['name'];
$dquantity = $row['quantity'];
$dmeasurement = $row['measurement'];
$dperUnitCost = $row['perUnitCost'];
$dtotalCost = $row['totalCost'];
// close connection
mysql_close();
?>Code: Select all
[b]<form id="form1" name="form1" method="post" action="suppliesUpdate.php">[/b]
[b] <input name="myID" type="hidden" id="myID" value="<? echo $row['supplies_PK'];?>">[/b]
<table width="712" height="89" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="5"> </td>
<td width="99" height="22">Code</td>
<td width="267">Description</td>
<td>Quantity</td>
<td width="111">Measurement</td>
<td width="92">Per Unit Cost</td>
<td width="72">Total Cost</td>
</tr>
<tr>
<td width="5"> </td>
<td width="99" height="30"><input name="code" type="text" class="formFieldsNum" id="code" tabindex="1" value="<?php echo $dcode; ?>" size="18" maxlength="8" /></td>
<td><input name="name" type="text" class="formFieldsDescription" id="name" tabindex="2" value="<?php echo $dname; ?>" size="50" maxlength="100"/></td>
<td width="66"><input name="quantity" type="text" class="formFieldsUnit" id="quantity" tabindex="3" value="<?php echo $dquantity; ?>" maxlength="4"/></td>
<td>
<select name="measurement" size="1" class="formFieldsDropDown" id="measurement" tabindex="4" />
<option value="<?php echo $dmeasurement;?>"><?php echo $dmeasurement;?></option>
<option value="kilogram(s)">kilogram(s)</option>
<option value="gram(s)">gram(s)</option>
<option value="Liter(s)">Liter(s)</option>
<option value="milliLiter(s)">milliLiter(s)</option>
<option value="lb(s)">lb(s)</option>
<option value="pc(s)">pc(s)</option>
<option value="gallon(s)">gallon(s)</option>
<option value="sack(s)">sack(s)</option>
<option value="ounce(s)">ounce(s)</option>
</select> </td>
<td><input name="perUnitCost" type="text" class="formFieldsCost" id="perUnitCost" maxlength="7" tabindex="5" value="<?php echo $dperUnitCost; ?>"/></td>
<td><input name="totalCost" type="text" class="formFieldsCost" id="totalCost" maxlength="7" tabindex="6" value="<?php echo $dtotalCost; ?>"/></td>
</tr>
<tr>
<td> </td>
<td height="33"> </td>
<td></td>
<td colspan="4"><div align="right">
<input name="update" type="submit" class="form-button" id="button2" value="Update Entry" onmouseover="this.style.color = 'white'" onmouseout="this.style.color = '#FF9900'" tabindex="7"/>
</div></td>
</tr>
</table>
</form>Code: Select all
<?php
//start session
session_start();
//include mysql_connection.php to connect to the database
require_once("connectSupplies.php");
if(!isset($_SESSION['user'])){
header("location:index.php");
}
$entry_id = $_POST['myID'];
$updatecode = $_POST['code'];
$updatename = $_POST['name'];
$updatequantity = $_POST['quantity'];
$updatemeasurement = $_POST['measurement'];
$updateperUnitCost = $_POST['perUnitCost'];
$updatetotalCost = $_POST['totalCost'];
$sql = "UPDATE tbl_supplies SET code='$updatecode', name='$updatename', quantity='$updatequantity', measurement='$updatemeasurement', perUnitCost='$updateperUnitCost', totalCost='$updatetotalCost' WHERE supplies_PK='$enrty_id'";
$result = mysql_query($sql) or die(mysql_error());
//show message and redirect if successfully update
if($result){
$updateSuccess = "<b><font color = \"green\">SUCCESS</font></b>: Entry with ID:". $enrty_id." Updated.";
header ("Refresh: 2; supplies.php");
}
else {
$updateError = "<b><font color = \"red\">ERROR</font></b>: Unable to update entry.";
}
?>Re: How to edit and delete the selected row
You have 2 typos in suppliesUpdate.php, it should be $entry_id not $enrty_id.
<?php
//start session
session_start();
//include mysql_connection.php to connect to the database
require_once("connectSupplies.php");
if(!isset($_SESSION['user'])){
header("location:index.php");
}
$entry_id = $_POST['myID'];
$updatecode = $_POST['code'];
$updatename = $_POST['name'];
$updatequantity = $_POST['quantity'];
$updatemeasurement = $_POST['measurement'];
$updateperUnitCost = $_POST['perUnitCost'];
$updatetotalCost = $_POST['totalCost'];
$sql = "UPDATE tbl_supplies SET code='$updatecode', name='$updatename', quantity='$updatequantity', measurement='$updatemeasurement', perUnitCost='$updateperUnitCost', totalCost='$updatetotalCost' WHERE supplies_PK='$enrty_id'";
$result = mysql_query($sql) or die(mysql_error());
//show message and redirect if successfully update
if($result){
$updateSuccess = "<b><font color = \"green\">SUCCESS</font></b>: Entry with ID:". $enrty_id." Updated.";
header ("Refresh: 2; supplies.php");
}
else {
$updateError = "<b><font color = \"red\">ERROR</font></b>: Unable to update entry.";
}
?>
Re: How to edit and delete the selected row
thanks Sindarin. I have corrected it into this
Still "SUCCESS: Entry with ID: Updated. "
Code: Select all
$sql = "UPDATE tbl_supplies SET code='$updatecode', name='$updatename', quantity='$updatequantity', measurement='$updatemeasurement', perUnitCost='$updateperUnitCost', totalCost='$updatetotalCost' WHERE supplies_PK=[b]'$entry_id[/b]'";
$result = mysql_query($sql) or die(mysql_error());
}
//show message and redirect if successfully update
if($result){
$updateSuccess = "<b><font color = \"green\">SUCCESS</font></b>: Entry with ID:". [b]$entry_id[/b]." Updated.";
header ("Refresh: 2; supplies.php");
}
else {
$updateError = "<b><font color = \"red\">ERROR</font></b>: Unable to update entry.";
}Re: How to edit and delete the selected row
To everyone who help. Most especially to Sindarin and Stryks. Thank you very much. i have fixed it. If you want the full code. Just post a request.
I hope this post will help some other aspiring programmers also.
Thanks a lot everyone. GOD bless DevNet
I hope this post will help some other aspiring programmers also.
Thanks a lot everyone. GOD bless DevNet