Jump to content

I need to write values from a Session form into a Flat File


kerbdog

Recommended Posts

:wtf:

 

I am pretty new to php and trying to teach myself.  I can't get the values from this form to write to my flat file called orders.txt:

 

browse_index.php

<?php 
include("includes/menu_members.php")
?>
<div id="content">

<h1>SHOPPING CART</h1>
<a href="browse_index.php">CLICK HERE TO CONTINUE SHOPPING</a>
  

<?php 

echo '
  <table border="0">
  <tr>
  <td><form id="f2" method="post"name="f2"><input type="submit" action="order_summary.php" name="submit2" value="submit order"></td>
  ';

  if(isset($_POST['submit']))
  {

  $itemname = $_POST['h1'];

  //echo $_SESSION['itemname'][$itemname];
  unset($_SESSION['itemqty'][$itemname]);
  unset($_SESSION['itemprice'][$itemname]);
  unset($_SESSION['itemname'][$itemname]);
  }

  echo "<br/><br/>";
  echo "<table border='8' bgcolor='#efefef'>";
  echo "<tr><th>Name</th><th>Quantity</th><th>Price</th><th>Subtotal</th></tr>";
  foreach($_SESSION['itemname'] as $key=>$value)
{

echo
'<tr><td><b>'.$_SESSION['itemname'][$key].'</b></td>
<td>'.$_SESSION['itemqty'][$key].'</td>
<td>$'.$_SESSION['itemprice'][$key].'</td>
<td name="subtotal">$'.($_SESSION['itemqty'][$key] * $_SESSION['itemprice'][$key]).'</td>
<td><form id="f1" method="post" name="f1"><input type="submit" name="submit" value =
"delete"><input type="hidden" name="h1" value='.$key.'></td></tr>'
;

}
  
?>

 

order_summary.php:

 

<?php
session_start ();

$date = date ("H:i jS F");

$outputstring = $date."/t"
.$_POST['h1']. ":"
.$_SESSION['itemqty'][$key]. ":"
.$_SESSION['subtotal'][$key]. ":"
."\n";

$fp = fopen("orders.txt","a");
fwrite($fp, $outputstring);
fclose($fp);
?>

 

Can someone direct me where I am going wrong???

I'm not sure why you're trying to mix session variables into this.  Make a simple form with whatever it is you're trying to submit on it.

 

In your order_summary read the data from $_POST[].

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.