I just started learning PHP a couple hours ago using these forums and now I am stuck. Thanks to the good people of this forum I have learned a lot, but I need some direct aide at this moment.
I have used Javascript to hide/reveal a short form. The intent of the form I am creating should store data into a text file, and display the stored content every time the submit button is hit. This is where the conflict lies.
Conflicts
- I have to press submit twice in order to display the contents of my text file
- Using the browser’s refresh button will duplicate saved data
*I have been experimenting with a few solutions, none of which were correct.
My Code (Below)
Device Manager<h2>DEVICE INVENTORY: MOBILE TEAM</h2>
<?php
$textfile = 'insert.txt';
if (file_exists($textfile) && is_readable($textfile))
{
$data = file($textfile);
}
//if ($i==0)
//for ($i=0; $i<1; $i++) {
//}
//else
for($i = 0; $i <= sizeof($data); $i++)
{
//separate each element and store in temp array
$tmp = explode(":", $data[$i]);
//assign each element to array
$data1[] = array('name' => $tmp[0], 'mdn' => $tmp[1], 'carrier' => $tmp[2], 'meid' => $tmp[3], 'version' => $tmp[4], 'date' => $tmp[5], 'notes' => $tmp[6], 'voice' => $tmp[7]);
}
echo "<table cellspacing='0' cellpadding='14'>";
if ($data1!=""){
echo "<tr><th style='background:#6699FF'>Device Name</th><th style='background:#6699FF'>MDN</th><th style='background:#6699FF'>Carrier</th><th style='background:#6699FF'>MEID/IMEI</th><th style='background:#6699FF'>OS Version</th><th style='background:#6699FF'>Received Date</th><th style='background:#6699FF'>Notes</th><th style='background:#6699FF'>Voice</th></tr>";
foreach ($data1 as $key => $row)
{
$name[$key]= $row['name'];
$mdn[$key]= $row['mdn'];
$carrier[$key]= $row['carrier'];
$meid[$key]= $row['meid'];
$version[$key]= $row['version'];
$date[$key]= $row['date'];
$notes[$key]= $row['notes'];
$voice[$key]= $row['voice'];
echo "<tr><td>{$name[$key]}</td><td>{$mdn[$key]}</td><td>{$carrier[$key]}</td><td>{$meid[$key]}</td><td>{$version[$key]}</td><td>{$date[$key]}</td><td>{$notes[$key]}</td><td>{$voice[$key]}</td></tr>";
}
}
echo "</table>";
?>
|