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???

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.