Jump to content

echo and insert into problem.


markymark

Recommended Posts

This php file cant echo in the 2nd php code, can anyone help me about this?

1st php code to connect into the 2nd php code

<?php
$Total = $Total + $Amount;
}
?>

</tr>
<tr>
    <td colspan="3" align="Right">Total</td>
    <td align ="Center"><?php echo number_format($Total,2);?></td>
</tr>

 

2nd php code

<?php
$db = mysql_connect("localhost", "root", "");
mysql_select_db("vinnex",$db);
$TransNo = $_POST['TransNo'];
$Username = $_POST['Username'];
$Date = $_POST['Date'];
$Total = $_GET['Total'];
echo $Total;
$sqltransaction = " INSERT INTO transaction (TransNo, Username, Date, Total)
						VALUES ('$TransNo', '$Username', '$Date', '$Total')";
$resulttransaction = mysql_query($sqltransaction);
?>

Link to comment
Share on other sites

The 1st php code it can generate the total amount but it isn't save in the database therefore i need to get the value of the $total in the 1st php code to the 2nd php code so that i could insert the value into the database. But i couldn't get it's value. =(

Link to comment
Share on other sites

Yes the code runs in separate php files. For example the Total is 900 and it is generated through the 1st php code via $Total = $Total + $Amount; so the total can Generate freely in the 1st form. By saving it i couldn't get the value of the $Total via saving it into the database. Ah well please look at my codes

 

orderproduct.php

<html>
<?php
$db = mysql_connect("localhost", "root", "");
mysql_select_db("vinnex",$db);
$sql = "SELECT * from temptransaction";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
  {
  $TransNo   =  $row['TransNo'];
  $Username  =  $row['Username'] ;
  $Firstname =  $row['Firstname'] ;
  $Date      =  $row['Date'] ;
  

   }

?>
<!--<meta http-equiv="" content="0;URL=orderproduct.php"/>-->

<body background="palered.jpg">
<form action="save.php" method="post" target="BottomRightFrame">
<table border="1" cellspacing="3"cellpadding="5" align="center">
<tr>
<th colspan="6"><h2>Order Form</h2></th>
</tr>
<tr>
<td align="Right">TransNo</td>
<td><input type="Text" name="TransNo" maxlength = "11" value="<?php echo $TransNo; ?>" readonly></td>
<td align="right">Date</td>
<td><input type="Text" name="Date" value="<?php echo $Date; ?>" readonly></td>

</tr>
<tr>
<td align="right">Username</td>
<td><input type="Text" name="Username" value="<?php echo $Username; ?>" readonly></td>
<td align="right">Name</td>
<td><input type="Text" name="name" value="<?php echo $Firstname; ?>" readonly></td>
</tr>
<tr>
<td align="center">Trans Details ID</td>
<td align="center">Product Code</td>
<td align="center">Per Cubic Meter</td>
<td align="center">Amount</td>

</tr>
<tr>
<?php
$db = mysql_connect("localhost", "root", "");
mysql_select_db("vinnex",$db);
$sqlresult = mysql_query("Select * From temptransdetails");
while($myrow = mysql_fetch_array($sqlresult))
{
  $TransDetailsID  =  $myrow['TransDetailsID'];
  $ProductCode  =  $myrow['ProductCode'] ;
  $PerCubicMeter =  $myrow['PerCubicMeter'] ;
  $Amount = $myrow['Amount'];
  
  ?>
<tr align="center">
<td><?php echo $TransDetailsID;?></td>
<td><?php echo $ProductCode;?></td>
<td><?php echo $PerCubicMeter;?></td>
<td><?php echo number_format($Amount,2);?></td>


<td valign="center">
<?php
echo"<a href=\"OrderEdit.php?orderdetailcodes=",$myrow[orderdetailcode]."\">Edit</a>";
?>
</td>
<td valign = "center">
<?php
echo"<a href=\"orderdelete.php?orderdetailcodes=",$myrow[orderdetailcode]."\">Delete</a>";
?>
</td>
</tr>
<?php
$Total = $Total + $Amount;
}
?>

</tr>
<tr>
<td colspan="3" align="Right">Total</td>
<td align ="Center"><?php echo number_format($Total,2);?></td>
</tr>
<tr>
<td colspan="6" align="Center"><input type="Submit" name="submit" value="Save">
<input type="Reset" name="reset" value="Reset"></td>
</tr>
</form>
<tr>
<form action="Order&Delivery.php" method="post" target="BottomRightFrame">
<td colspan="6" align="Center"><INPUT TYPE="Submit" name ="Submit" value="Select Product">

</tr>

</table>
</form>
</body>
</html>

 

save.php

<html>
<?php
$db = mysql_connect("localhost", "root", "");
mysql_select_db("vinnex",$db);
$TransNo = $_POST['TransNo'];
$Username = $_POST['Username'];
$Date = $_POST['Date'];
$Total = $_GET['Total'];
echo $Total;
$sqltransaction = " INSERT INTO transaction (TransNo, Username, Date, Total)
                            VALUES ('$TransNo', '$Username', '$Date', '$Total')";
$resulttransaction = mysql_query($sqltransaction);

$TransDetailsID = $_POST['TransDetailsID'];
$TransNo = $_POST['TransNo'];
$ProductCode = $_POST['ProductCode'];
$PerCubicMeter = $_POST['PerCubicMeter'];
$Amount = $_POST['Amount'];
$sql1 = "SELECT from temptransdetails where TransDetailsID = '$TransDetailsID'";
$result1 = mysql_query($sql1);
while($row1 = mysql_fetch_array($result1))
  {
  $TransDetailsID   =  $row1['TransDetailsID'];
  $TransNo   =  $row1['TransNo'];
  $ProductCode   =  $row1['ProductCode'];
  $PerCubicMeter   =  $row1['PerCubicMeter'];
  $Amount   =  $row1['Amount'];
    }
$sqltransdetails = " INSERT INTO transdetails (TransDetailsID, TransNo, ProductCode, PerCubicMeter, Amount)
                            VALUES ('$TransDetails', '$TransNo', '$ProductCode', '$PerCubicMeter', '$Amount')";
$resulttransdetails = mysql_query($sqltransdetails);
?>
<!--<meta http-equiv="refresh" content="1;url=home.html"/>-->
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.