about updating records in MYSQL using PHP
Posted: Sun Sep 05, 2010 6:55 am
echo "<h2> transaction description </h2>";
echo "<hr>";
//Connection to the data base.
$connect = mysql_connect ("localhost","root","") or die ("error");
mysql_select_db ("guestbook") or die ("eroor connecting Database");
$queryget = mysql_query ("select * from report ORDER BY Transaction_Number DESC LIMIT 5" ) or die (" error with table");
//this while loop will get the information from the data base and it will be displayed on the web interface.
echo "<hr>";
while ( $row = mysql_fetch_assoc ($queryget) ){
$Customername = $row ['Customer_name'];
$Transaction_Number = $row ['Transaction_Number'];
$Price = $row ['Price'];
$Weight = $row ['Weight'];
$date = $row ['Date'];
$time = $row ['Time'];
echo"
<table>
<tr>
<td>
<b> Customer name : $Customername</b>
</td>
</tr>
<tr>
<td>
<b> Weight : $Weight</b>
<p>
<input type='submit' name='submit2' value='Void'>
</td>
</tr>
";
echo "<hr>";
}
// to get the summation of the parameter weight.
$query = "SELECT SUM(Weight) FROM report ";
$result = mysql_query($query) or die(mysql_error());
// Print out result
while($row = mysql_fetch_array($result)){
echo "Total ". $row['SUM(Weight)'];
echo "<br />";
}
// this will post the input data into the data base.
if (isset($_POST['submit1']))
{
$Customername = $_POST['Customer_name'];
$Transaction_Number = $_POST['Transaction_Number'];
$Price = $_POST['Price'];
$Weight = $_POST['Weight'];
$date = date("Y-m-d");
$time = date("H:i:s");
$status = 'Completed'; // this is to indicate that the transaction has done.
if ($Customername&&$Transaction_Number&&$Price&&$Weight )
{
$querypost = mysql_query (" INSERT INTO report VALUES ('$Customername', '$Transaction_Number', '$Price', '$Weight','$date','$time','$status')");
echo "Please wait... <meta http-equiv='refresh' content='4'>";
}
else
echo " fill out all fileds";
}
// when the operator clicked the void button on the web interface,that perticular transaction has to be marked as cancel.this part is not working for it.
if (isset($POST['submit2']))
{
$querypost = mysql_query ("UPDATE report SET
Status = 'Cancel'
WHERE
Customer name = '???', Transaction_Number = '???',Price = '???', Date = '???', Time = '???'AND Weight = '???'");
}
else
echo " Updating process is not sucessfull";
echo"
<form action='guestbook.php' method='POST'>
<table width= '100 %'>
<tr>
<td>
Customer name
</td>
<td>
<input type='text' name='Customer_name' maxlength='30'>
</td>
</tr>
<tr>
<td>
Transaction Number
</td>
<td>
<input type='int' name='Transaction_Number' maxlength='25'>
</td>
</tr>
<tr>
<td>
Price
</td>
<td>
<input type='int' name='Price' maxlength='25'>
</td>
</tr>
<tr>
<td valign='top'>
Weight
<td>
<input type='int' name='Weight' maxlength='25'>
<p>
<input type='submit' name='submit1' value='Confirm'>
</td>
</tr>
</table>
</form>
"
?>
Hi;
I am trying to create a system for business transactions. if some one enters a new transaction through the web interface, it will save in the data base and als it will be marked as completed. If some one wants to void (cancel) a past transaction, the perosn who is invloved in sales have to click the void button.
then the data base will be updated the completed staus in to cancel. no changes will be done for the other parameters such as customer name, date, weight etc.. That is my requirment. unfortunateley my updating part is not working for the void button. The idea of this change is to split the canceld and completed transaction in to two for the report.
my friends asked me to use a check box but i realized the actions is almost same like this. I felt like i am missing a logic to select a perticular transaction from the web.
Does any one have a better solution for this.
Thank you.
Please refer to my attachments.
Shehan Fernando
echo "<hr>";
//Connection to the data base.
$connect = mysql_connect ("localhost","root","") or die ("error");
mysql_select_db ("guestbook") or die ("eroor connecting Database");
$queryget = mysql_query ("select * from report ORDER BY Transaction_Number DESC LIMIT 5" ) or die (" error with table");
//this while loop will get the information from the data base and it will be displayed on the web interface.
echo "<hr>";
while ( $row = mysql_fetch_assoc ($queryget) ){
$Customername = $row ['Customer_name'];
$Transaction_Number = $row ['Transaction_Number'];
$Price = $row ['Price'];
$Weight = $row ['Weight'];
$date = $row ['Date'];
$time = $row ['Time'];
echo"
<table>
<tr>
<td>
<b> Customer name : $Customername</b>
</td>
</tr>
<tr>
<td>
<b> Weight : $Weight</b>
<p>
<input type='submit' name='submit2' value='Void'>
</td>
</tr>
";
echo "<hr>";
}
// to get the summation of the parameter weight.
$query = "SELECT SUM(Weight) FROM report ";
$result = mysql_query($query) or die(mysql_error());
// Print out result
while($row = mysql_fetch_array($result)){
echo "Total ". $row['SUM(Weight)'];
echo "<br />";
}
// this will post the input data into the data base.
if (isset($_POST['submit1']))
{
$Customername = $_POST['Customer_name'];
$Transaction_Number = $_POST['Transaction_Number'];
$Price = $_POST['Price'];
$Weight = $_POST['Weight'];
$date = date("Y-m-d");
$time = date("H:i:s");
$status = 'Completed'; // this is to indicate that the transaction has done.
if ($Customername&&$Transaction_Number&&$Price&&$Weight )
{
$querypost = mysql_query (" INSERT INTO report VALUES ('$Customername', '$Transaction_Number', '$Price', '$Weight','$date','$time','$status')");
echo "Please wait... <meta http-equiv='refresh' content='4'>";
}
else
echo " fill out all fileds";
}
// when the operator clicked the void button on the web interface,that perticular transaction has to be marked as cancel.this part is not working for it.
if (isset($POST['submit2']))
{
$querypost = mysql_query ("UPDATE report SET
Status = 'Cancel'
WHERE
Customer name = '???', Transaction_Number = '???',Price = '???', Date = '???', Time = '???'AND Weight = '???'");
}
else
echo " Updating process is not sucessfull";
echo"
<form action='guestbook.php' method='POST'>
<table width= '100 %'>
<tr>
<td>
Customer name
</td>
<td>
<input type='text' name='Customer_name' maxlength='30'>
</td>
</tr>
<tr>
<td>
Transaction Number
</td>
<td>
<input type='int' name='Transaction_Number' maxlength='25'>
</td>
</tr>
<tr>
<td>
Price
</td>
<td>
<input type='int' name='Price' maxlength='25'>
</td>
</tr>
<tr>
<td valign='top'>
Weight
<td>
<input type='int' name='Weight' maxlength='25'>
<p>
<input type='submit' name='submit1' value='Confirm'>
</td>
</tr>
</table>
</form>
"
?>
Hi;
I am trying to create a system for business transactions. if some one enters a new transaction through the web interface, it will save in the data base and als it will be marked as completed. If some one wants to void (cancel) a past transaction, the perosn who is invloved in sales have to click the void button.
then the data base will be updated the completed staus in to cancel. no changes will be done for the other parameters such as customer name, date, weight etc.. That is my requirment. unfortunateley my updating part is not working for the void button. The idea of this change is to split the canceld and completed transaction in to two for the report.
my friends asked me to use a check box but i realized the actions is almost same like this. I felt like i am missing a logic to select a perticular transaction from the web.
Does any one have a better solution for this.
Thank you.
Please refer to my attachments.
Shehan Fernando