Author Topic: Forms PHP + Javascript Help  (Read 923 times)

phpBeginner1

  • New Member
  • *
  • Posts: 20
  • Karma: 0
    • View Profile
Re: Forms PHP + Javascript Help
« Reply #15 on: June 04, 2012, 06:27:22 PM »
I have rearranged my code, and now my counter and posting with printing works fine. But I still another conflict. Refreshing the page will resubmit the form data, creating duplicates. How do I solve this issue? I've been looking into md5, creating an invisible form field and attaching a randomized number into the field, and then creating if statements to make sure that the values match (which they won't if you refresh). But I do not know how to really implement it. Everyone says it is easy, but it seems a bit difficult. Any suggestions?

phpBeginner1

  • New Member
  • *
  • Posts: 20
  • Karma: 0
    • View Profile
Re: Forms PHP + Javascript Help
« Reply #16 on: June 04, 2012, 06:31:55 PM »
My code so far (Part 1)

Code: [Select]
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Device Manager</title>

<!-- Call JQuery -->
<script src="http://www.acmeous.com/tutorials/demo/acmeousCollapsibleLists/acmeousCollapsibleLists.js"
type="text/javascript"></script>


<!-- Setup Event Listener -->
<script type="text/javascript"><!--
if (window.addEventListener) {
window.addEventListener("load", function(){makeCollapsible(document.getElementById('addDevice'), 0);}, false);
} else if (window.attachEvent) {
window.attachEvent("onload", function(){makeCollapsible(document.getElementById('addDevice'), 1);});
} else {
window.onload = function(){makeCollapsible(document.getElementById('addDevice'), 1);};
}
-->
</script>

</head>

<body>

<?php

error_reporting(E_ALL); //E_ALL ^ E_NOTICE
ini_set('display_errors','1');

?>



<div align="center">
<table border="0" cellpadding="0" cellspacing="0" width="750" height="500">
<!-- MSTableType="layout" -->
<tr>
<td valign="top" height="320">
<!-- MSCellType="ContentBody" -->
<table cellpadding="0" cellspacing="0" width="750" height="320">
<!-- MSCellFormattingTableID="1" -->
<tr>
<td height="310">
<table cellpadding="0" cellspacing="0" border="0" width="100%" height="100%">
<tr>
<td valign="top" height="100%" width="100%">
<!-- MSCellFormattingType="content" -->
</td>
</tr>
</table>
</td>
</tr>

<tr>
<td height="10" width="750">
<img alt="" width="1" height="10" src="MsSpacer.gif"></td>
</tr>
</table>
</td>
</tr>


<tr>


<td valign="top" height="180" width="750">
<!-- MSCellType="ContentBody" -->

<!-- Create id, hide and finalize expandable content -->
<ul id="addDevice">
  <li>Add New Device<ul>

phpBeginner1

  • New Member
  • *
  • Posts: 20
  • Karma: 0
    • View Profile
Re: Forms PHP + Javascript Help
« Reply #17 on: June 04, 2012, 06:32:36 PM »
Code part 2

Code: [Select]
<?php

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

$platform$_POST['platform']; //defining variable before use
$owner$_POST['owner']; //defining variable before use

if ($platform=="Android") {
if ($owner=="Mobile Team") {
//prepare 'mtand.txt' file for data
$fh fopen("mtand.txt","a+") or die("File Close"); }
}

if ($platform=="iOS") {
if ($owner=="Mobile Team") {
//prepare 'mtios.txt' file for data
$fh fopen("mtios.txt","a+") or die("File Close"); }
}

if ($platform=="MISC") {
if ($owner=="Mobile Team") {
//prepare 'mtmisc.txt' file for data
$fh fopen("mtmisc.txt","a+") or die("File Close"); }
}

if ($platform=="Android") {
if ($owner=="Biz Dev") {
//prepare 'bdand.txt' file for data
$fh fopen("bdand.txt","a+") or die("File Close"); }
}

if ($platform=="iOS") {
if ($owner=="Biz Dev") {
//prepare 'bdios.txt' file for data
$fh fopen("bdios.txt","a+") or die("File Close"); }
}

if ($platform=="MISC") {
if ($owner=="Biz Dev") {
//prepare 'bdmisc.txt' file for data
$fh fopen("bdmisc.txt","a+") or die("File Close"); }
}


$name$_POST['name'];
$mdn$_POST['mdn'];
$carrier$_POST['carrier'];
$meid$_POST['meid'];
$version$_POST['version'];
$date$_POST['date'];
$notes$_POST['notes'];
$voice$_POST['voice'];

/* $platform= $_POST['platform'] */
/* $owner= $_POST['owner'] */

//setup implementation rules for notes
$notes=stripslashes($notes);

//implement validation
if (empty($name)) {
print "<font color=#E00000> *Error: Must Fill Out All Fields! Mobile Device Information Not Stored.<br>"; }
elseif (empty($mdn)) {
print "<font color=#E00000> *Error: Must Fill Out All Fields! Mobile Device Information Not Stored.<br>"; }
elseif (empty($carrier)) {
print "<font color=#E00000> *Error: Must Fill Out All Fields! Mobile Device Information Not Stored.<br>"; }
elseif (empty($meid)) {
print "<font color=#E00000> *Error: Must Fill Out All Fields! Mobile Device Information Not Stored.<br>"; }
elseif (empty($version)) {
print "<font color=#E00000> *Error: Must Fill Out All Fields! Mobile Device Information Not Stored.<br>"; }
elseif (empty($date)) {
print "<font color=#E00000> *Error: Must Fill Out All Fields! Mobile Device Information Not Stored.<br>"; }

else {


//assemble the data into a line variable
$data$name ":" $mdn ":" $carrier ":" $meid ":" $version ":" $date ":" $notes ":" $voice ":" "\r\n";

//Figure out what choice was made so that data can be written to correct text file
if ($platform=="Android") {
 if ($owner=="Mobile Team") { 
print "<font color=#6699FF> *Successfully Added Device To The <font color=#E00000>$owner ($platform)<font color=#6699FF> Category!<br>";

//write the data to the file
fwrite($fh$data);

$mtandcount ''//defining variable before use. Variable is used to count devices

if ($mtandcount == null) { //setting initial value to 0, will increment with every added device
$mtandcount 0; }

//counter for devices
if ($fh fopen('mtand.txt''r')) { 
while (!feof($fh)) {
if (fgets($fh)) {
$mtandcount++;
}
}
}
/* adding a print or echo line here will show that $mtandcount is increasing properly, however, it does not reflect at the top of the script */

}
}


//Figure out what choice was made so that data can be written to correct text file
if ($platform=="iOS") {
 if ($owner=="Mobile Team") { 
print "<font color=#6699FF> *Successfully Added Device To The <font color=#E00000>$owner ($platform)<font color=#6699FF> Category!<br>";

//write the data to the file
fwrite($fh$data);
}
}

//Figure out what choice was made so that data can be written to correct text file
if ($platform=="MISC") {
 if ($owner=="Mobile Team") { 
print "<font color=#6699FF> *Successfully Added Device To The <font color=#E00000>$owner ($platform)<font color=#6699FF> Category!<br>";

//write the data to the file
fwrite($fh$data);
}
}

//Figure out what choice was made so that data can be written to correct text file
if ($platform=="Android") {
 if ($owner=="Biz Dev") { 
print "<font color=#6699FF> *Successfully Added Device To The <font color=#E00000>$owner ($platform)<font color=#6699FF> Category!<br>";

//write the data to the file
fwrite($fh$data);
}
}

//Figure out what choice was made so that data can be written to correct text file
if ($platform=="iOS") {
 if ($owner=="Biz Dev") { 
print "<font color=#6699FF> *Successfully Added Device To The <font color=#E00000>$owner ($platform)<font color=#6699FF> Category!<br>";

//write the data to the file
fwrite($fh$data);
}
}

//Figure out what choice was made so that data can be written to correct text file
if ($platform=="MISC") {
 if ($owner=="Biz Dev") { 
print "<font color=#6699FF> *Successfully Added Device To The <font color=#E00000>$owner ($platform)<font color=#6699FF> Category!<br>";

//write the data to the file
fwrite($fh$data);
}
}

//close the file
fclose($fh);      

}
 
?>



<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body{
font: 10px Verdana, Arial, Helvetica, sans-serif;
}
</style>


<?php 

$output ''//defining variable before use. Line 255

if($output!=""){ echo $output; } ?>

<form action = "<? echo $_SERVER['PHP_SELF']?>" method = "post">
<div style="border:2px solid #cccccc;margin:8px;padding:8px;width:600px;">
<table width="80%">
<tr><td><b>Enter Device Name: </b></td><td><input name="name" type="text" style="width:200px;" /></td></tr>
<tr><td><b>Enter MDN: </b></td><td><input name="mdn" type="text" style="width:200px;" /></td></tr>
<tr><td><b>Enter Carrier: </b></td><td><input name="carrier" type="text" style="width:200px;" /></td></tr>
<tr><td><b>Enter MEID/IMEI: </b></td><td><input name="meid" type="text" style="width:200px;" /></td></tr>
<tr><td><b>Enter OS Version: </b></td><td><input name="version" type="text" style="width:200px;" /></td></tr>
<tr><td><b>Enter Received Date: </b></td><td><input name="date" type="text" style="width:200px;" /></td></tr>
<tr><td><b>Enter Notes: </b></td><td><input name="notes" type="text" style="width:200px;" /></td></tr>
<tr><td><b>Is Voice Enabled (Yes/No):</b></td><td>
<select name="voice" style="width:200px;">
<option>Yes</option>
<option>No</option>
</select></td></tr>

<tr><td><b>Select Device Platform (Android/iOS/MISC):</b></td><td>
<select name="platform" style="width:200px;">
<option>Android</option>
<option>iOS</option>
<option>MISC</option>
</select></td></tr>

<tr><td><b>Select Device Owner (Mobile Team/Biz Dev):</b></td><td>
<select name="owner" style="width:200px;">
<option>Mobile Team</option>
<option>Biz Dev</option>
</select></td></tr>
</table>
<input type="submit" name="submit" value="Update" />
</div>
</form>

</tr>
</table>
        </ul>
    </li>
</ul>
</div>

<?php

if ($mtandcount == null) { //setting initial value to 0, will increment with every added device
$mtandcount 0; }

$fh fopen("mtand.txt","a+") or die("File Close"); 

//counter for devices
if ($fh fopen('mtand.txt''r')) { 
while (!feof($fh)) {
if (fgets($fh)) {
}
}
}
print "<font size='6'>DEVICE INVENTORY (Android): MOBILE TEAM ($mtandcount)</font><br>";

//close the file
fclose($fh);

$textfile 'mtand.txt';
$data ''//defining variable before use
$data1 ''//defining variable before use

      
if (file_exists($textfile) && is_readable($textfile))      
      {         
         
$file file($textfile);      

         foreach (
$file as $line)
         {
            
//separate each element and store in temp array.      
            
$tmp explode(":"$line);               

            
//assign each element to array.        
            
$data[] = 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 ($data!=""){
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 ($data 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>";
?>
   

</body>

</html>
 

phpBeginner1

  • New Member
  • *
  • Posts: 20
  • Karma: 0
    • View Profile
Re: Forms PHP + Javascript Help
« Reply #18 on: June 08, 2012, 08:26:02 PM »
Ok, I am back! I figured everything out. I wanted to share what the fix was so that others like me will know. If you recall, I was looking for help on how to prevent data from being submitted again after someone refreshed the page. This is for one page, so no redirects or other pages were used. This is also for saving data to a text file.

First you want to add this before your form.
PHP Code: [Select]
if($output!=""){ echo $output; } 

$secret=md5(uniqid(rand(), true)); //generate a random value
$_SESSION['FORM_SECRET'] = $secret//set the session


At the top of the page, as was suggested by some of the people here be sure to start your session. When I say top of the page, I mean literally line 1. (I have to clarify this, because it is rarely clarified anywhere else. I looked! **scours google**) Start the session by adding the line
PHP Code: [Select]
session_start(); //start a session. This is all in <?php> tags.

Now for the final part. Add this before you write data to your file. It goes in that area.
PHP Code: [Select]

	
//Retrieve the value of the hidden field
	
$form_secret $_POST['form_secret']; /* isset($_POST["form_secret"])?$_POST["form_secret"]:''; */

	
if(isset(
$_SESSION['FORM_SECRET'])) {
	
if(
strcasecmp($form_secret$_SESSION['FORM_SECRET']) === 0) { /* if($_POST['secret'] == $_SESSION['secret']) { */


And unset your session whereever you feel necessary.
PHP Code: [Select]
unset ($_SESSION["FORM_SECRET"]);

Now refresh will not double submit. Took a while, but I got it. And now I am sharing the love.


phpBeginner1

  • New Member
  • *
  • Posts: 20
  • Karma: 0
    • View Profile
Re: Forms PHP + Javascript Help
« Reply #19 on: June 08, 2012, 08:37:48 PM »
Ok, now for round 2! Now that my form can save and display data all on one page, using a text file...I need help with editing bad entries. I did not think about this until now. Now that I have a little handle on things, I tried my hand out with the little knowledge I do have, but it is not working quite right. Where I am having difficulties is that I would like a delete button (I used text though) to appear and remain upon displaying the contents of my textfiles (database). I know that all this will be easier with mySQL, but I want to master this. If anyone can help me, that would be nice. What I have tried so far is this,

This is the code I came up with...
PHP Code: [Select]
	
$textfile 'mtand.txt';
      if (
file_exists($textfile) && is_readable($textfile))      
      { 

	
$delete = @$_GET['delete']; 
	
$file_name "mtand.txt";
	
$size filesize($file_name);
	
$textFile file($file_name);
	
$lines count($textFile);
 
	
if(
$size == "0"
	

	
/* Do no action. There is no data written to the file */
	
exit; 
	
	

	
}

if(
$delete != "" && $delete >! $lines || $delete === '0') { 
    
$textFile[$delete] = ""
    
$fileUpdate fopen($file_name"wb"); 
    for(
$a=0$a<$lines$a++) { 
           
fwrite($fileUpdate$textFile[$a]); 
    } 
    
fclose($fileUpdate); 
   
header("Location:indexNew.htm"); 

} else

foreach(
$textFile as $key => $val) { 

$line = @$line $val "<a href =?delete=$key> [DELETE] </a><br/>";
	


echo 
$line;       


As you can see, I setup a variable for my text file in order to confirm that it exists. I setup some more variables, including one variable that will read whether or not there is actually anything in the text file at all. And then I begin a process that will read my text file, gather the information and then delete. Here is my conflict. (1) I am not sure if I need to repeat this multiple times. (2) data is being deleted, but I actually do not understand how. From my experimentations, I have to link to my page URL + ?delete=x in order for this to work. But while doing this, I cannot reprocess my form afterwards. (3) What am I missing here? I am on the correct track, right? I do not want one instance of delete button (text), I want the opportunity to delete any data that is stored at any time because the button is there always. How do i do this? I will keep tinkering around as usual. But I do need some help. My code is posted in the next sets of posts.

phpBeginner1

  • New Member
  • *
  • Posts: 20
  • Karma: 0
    • View Profile
Re: Forms PHP + Javascript Help
« Reply #20 on: June 08, 2012, 08:40:12 PM »
Part One. I have BOLDED the piece of code I am working on. It is in the first half of the code.

Code: [Select]
<?php
session_start
(); //start a session

error_reporting(E_ALL); //E_ALL ^ E_NOTICE
ini_set('display_errors','1'); //Initialize custom debugging function
?>


<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Device Manager</title>

<!-- Call JQuery -->
<script src="http://www.acmeous.com/tutorials/demo/acmeousCollapsibleLists/acmeousCollapsibleLists.js"
type="text/javascript"></script>


<!-- Setup Event Listener -->
<script type="text/javascript"><!--
if (window.addEventListener) {
window.addEventListener("load", function(){makeCollapsible(document.getElementById('addDevice'), 0);}, false);
} else if (window.attachEvent) {
window.attachEvent("onload", function(){makeCollapsible(document.getElementById('addDevice'), 1);});
} else {
window.onload = function(){makeCollapsible(document.getElementById('addDevice'), 1);};
}
-->
</script>

</head>

<body>

<?php

print "<font size='6'>DEVICE INVENTORY (Android): MOBILE TEAM</font><br>";

$textfile 'mtand.txt';
$data ''//defining variable before use

      
if (file_exists($textfile) && is_readable($textfile))      
      {         
         
$file file($textfile);      

         foreach (
$file as $line)
         {
            
//separate each element and store in temp array.      
            
$tmp explode(":"$line);               

            
//assign each element to array.        
            
$data[] = 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 ($data!=""){
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 ($data 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>";

[
b] $textfile 'mtand.txt';
      if (
file_exists($textfile) && is_readable($textfile))      
      { 

$delete = @$_GET['delete']; 
$file_name "mtand.txt";
$size filesize($file_name);
$textFile file($file_name);
$lines count($textFile);
 
if($size == "0"

/* Do no action. There is no data written to the file */
exit; 

}

if(
$delete != "" && $delete >! $lines || $delete === '0') { 
    
$textFile[$delete] = ""
    
$fileUpdate fopen($file_name"wb"); 
    for(
$a=0$a<$lines$a++) { 
           
fwrite($fileUpdate$textFile[$a]); 
    } 
    
fclose($fileUpdate); 
   
header("Location:indexNew.htm"); 

} else

foreach(
$textFile as $key => $val) { 

$line = @$line $val "<a href =?delete=$key> [DELETE] </a><br/>";


echo 
$line;    [/b]   

?>


<?php

print "<font size='6'>DEVICE INVENTORY (iOS): MOBILE TEAM</font><br>";

$textfile 'mtios.txt';
$data ''//defining variable before use

      
if (file_exists($textfile) && is_readable($textfile))      
      {         
         
$file file($textfile);      

         foreach (
$file as $line)
         {
            
//separate each element and store in temp array.      
            
$tmp explode(":"$line);               

            
//assign each element to array.        
            
$data[] = 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 ($data!=""){
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 ($data 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>";
?>


<?php

print "<font size='6'>DEVICE INVENTORY (MISC): MOBILE TEAM</font><br>";

$textfile 'mtmisc.txt';
$data ''//defining variable before use

      
if (file_exists($textfile) && is_readable($textfile))      
      {         
         
$file file($textfile);      

         foreach (
$file as $line)
         {
            
//separate each element and store in temp array.      
            
$tmp explode(":"$line);               

            
//assign each element to array.        
            
$data[] = 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 ($data!=""){
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 ($data 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>";
?>


<?php

print "<font size='6'>DEVICE INVENTORY (Android): BIZ DEV</font><br>";

$textfile 'bdand.txt';
$data ''//defining variable before use

      
if (file_exists($textfile) && is_readable($textfile))      
      {         
         
$file file($textfile);      

         foreach (
$file as $line)
         {
            
//separate each element and store in temp array.      
            
$tmp explode(":"$line);               

            
//assign each element to array.        
            
$data[] = 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 ($data!=""){
echo "<tr><th style='background:#A6A6A6'>Device Name</th><th style='background:#A6A6A6'>MDN</th><th style='background:#A6A6A6'>Carrier</th><th style='background:#A6A6A6'>MEID/IMEI</th><th style='background:#A6A6A6'>OS Version</th><th style='background:#A6A6A6'>Received Date</th><th style='background:#A6A6A6'>Notes</th><th style='background:#A6A6A6'>Voice</th></tr>";
foreach ($data 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>";
?>


<?php

print "<font size='6'>DEVICE INVENTORY (iOS): BIZ DEV</font><br>";

$textfile 'bdios.txt';
$data ''//defining variable before use

      
if (file_exists($textfile) && is_readable($textfile))      
      {         
         
$file file($textfile);      

         foreach (
$file as $line)
         {
            
//separate each element and store in temp array.      
            
$tmp explode(":"$line);               

            
//assign each element to array.        
            
$data[] = 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 ($data!=""){
echo "<tr><th style='background:#A6A6A6'>Device Name</th><th style='background:#A6A6A6'>MDN</th><th style='background:#A6A6A6'>Carrier</th><th style='background:#A6A6A6'>MEID/IMEI</th><th style='background:#A6A6A6'>OS Version</th><th style='background:#A6A6A6'>Received Date</th><th style='background:#A6A6A6'>Notes</th><th style='background:#A6A6A6'>Voice</th></tr>";
foreach ($data 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>";
?>


<?php

print "<font size='6'>DEVICE INVENTORY (MISC): BIZ DEV</font><br>";

$textfile 'bdmisc.txt';
$data ''//defining variable before use

      
if (file_exists($textfile) && is_readable($textfile))      
      {         
         
$file file($textfile);      

         foreach (
$file as $line)
         {
            
//separate each element and store in temp array.      
            
$tmp explode(":"$line);               

            
//assign each element to array.        
            
$data[] = 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 ($data!=""){
echo "<tr><th style='background:#A6A6A6'>Device Name</th><th style='background:#A6A6A6'>MDN</th><th style='background:#A6A6A6'>Carrier</th><th style='background:#A6A6A6'>MEID/IMEI</th><th style='background:#A6A6A6'>OS Version</th><th style='background:#A6A6A6'>Received Date</th><th style='background:#A6A6A6'>Notes</th><th style='background:#A6A6A6'>Voice</th></tr>";
foreach ($data 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>";
?>


<div align="center">
<table border="0" cellpadding="0" cellspacing="0" width="750" height="500">
<!-- MSTableType="layout" -->
<tr>
<td valign="top" height="320">
<!-- MSCellType="ContentBody" -->
<table cellpadding="0" cellspacing="0" width="750" height="320">
<!-- MSCellFormattingTableID="1" -->
<tr>
<td height="310">
<table cellpadding="0" cellspacing="0" border="0" width="100%" height="100%">
<tr>
<td valign="top" height="100%" width="100%">
<!-- MSCellFormattingType="content" -->
</td>
</tr>
</table>
</td>
</tr>

<tr>
<td height="10" width="750">
<img alt="" width="1" height="10" src="MsSpacer.gif"></td>
</tr>
</table>
</td>
</tr>


<tr>


<td valign="top" height="180" width="750">
<!-- MSCellType="ContentBody" -->

<!-- Create id, hide and finalize expandable content -->
<ul id="addDevice">
  <li>Add New Device<ul>

phpBeginner1

  • New Member
  • *
  • Posts: 20
  • Karma: 0
    • View Profile
Re: Forms PHP + Javascript Help
« Reply #21 on: June 08, 2012, 08:41:17 PM »
Part 2

PHP Code: [Select]
<?php
	
	


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


	
$platform$_POST['platform']; //defining variable before use
	
$owner$_POST['owner']; //defining variable before use

	
if (
$platform=="Android") {
	
	
if (
$owner=="Mobile Team") {
	
//prepare 'mtand.txt' file for data
	

	
$fh fopen("mtand.txt","a+") or die("File Close"); }
	
}

	
if (
$platform=="iOS") {
	
	
if (
$owner=="Mobile Team") {
	
//prepare 'mtios.txt' file for data
	

	
$fh fopen("mtios.txt","a+") or die("File Close"); }
	
}

	
if (
$platform=="MISC") {
	
	
if (
$owner=="Mobile Team") {
	
//prepare 'mtmisc.txt' file for data
	

	
$fh fopen("mtmisc.txt","a+") or die("File Close"); }
	
}

	
if (
$platform=="Android") {
	
	
if (
$owner=="Biz Dev") {
	
//prepare 'bdand.txt' file for data
	

	
$fh fopen("bdand.txt","a+") or die("File Close"); }
	
}

	
if (
$platform=="iOS") {
	
	
if (
$owner=="Biz Dev") {
	
//prepare 'bdios.txt' file for data
	

	
$fh fopen("bdios.txt","a+") or die("File Close"); }
	
}

	
if (
$platform=="MISC") {
	
	
if (
$owner=="Biz Dev") {
	
//prepare 'bdmisc.txt' file for data
	

	
$fh fopen("bdmisc.txt","a+") or die("File Close"); }
	
}


	
$name$_POST['name'];
	
	

	
$mdn$_POST['mdn'];
	
	

	
$carrier$_POST['carrier'];
	
	

	
$meid$_POST['meid'];
	
$version$_POST['version'];
	
$date$_POST['date'];
	
$notes$_POST['notes'];
	
$voice$_POST['voice'];

	
/* $platform= $_POST['platform'] */
	
/* $owner= $_POST['owner'] */

	
//setup implementation rules for notes
	
$notes=stripslashes($notes);

	
//implement validation
	
if (empty(
$name)) {
	
print 
"<font color=#E00000><b> *Error: Must Fill Out All Fields! Mobile Device Information Not Stored</b><br>"; }
	
elseif (empty(
$mdn)) {
	
print 
"<font color=#E00000><b> *Error: Must Fill Out All Fields! Mobile Device Information Not Stored</b><br>"; }
	
elseif (empty(
$carrier)) {
	
print 
"<font color=#E00000><b> *Error: Must Fill Out All Fields! Mobile Device Information Not Stored</b><br>"; }
	
elseif (empty(
$meid)) {
	
print 
"<font color=#E00000><b> *Error: Must Fill Out All Fields! Mobile Device Information Not Stored</b><br>"; }
	
elseif (empty(
$version)) {
	
print 
"<font color=#E00000><b> *Error: Must Fill Out All Fields! Mobile Device Information Not Stored</b><br>"; }
	
elseif (empty(
$date)) {
	
print 
"<font color=#E00000><b> *Error: Must Fill Out All Fields! Mobile Device Information Not Stored</b><br>"; }
	

	
else {

	
//Retrieve the value of the hidden field
	
$form_secret $_POST['form_secret']; /* isset($_POST["form_secret"])?$_POST["form_secret"]:''; */

	
if(isset(
$_SESSION['FORM_SECRET'])) {
	
if(
strcasecmp($form_secret$_SESSION['FORM_SECRET']) === 0) { /* if($_POST['secret'] == $_SESSION['secret']) { */

	
$mtandcount '';
	
$mtioscount '';
	
$mtmisccount '';
	
$bdandcount '';
	
$bdioscount '';
	
$bdmisccount '';

	
//assemble the data into a line variable
	
	

	
$data$name ":" $mdn ":" $carrier ":" $meid ":" $version ":" $date ":" $notes ":" $voice ":" "\r\n";
	
	


	
//Figure out what choice was made so that data can be written to correct text file
	
if (
$platform=="Android") {
	

	
	
 if (
$owner=="Mobile Team") { 
	
	

	
	
print 
"<font color=#6699FF><b> *Successfully Added Device To <font color=#E00000>$owner ($platform)<font color=#6699FF> Category!</b><br>";
	
	

	
	
	
//write the data to the file
	
	

	
	
	
fwrite($fh$data);
	
	
	

	
	
	
//counter for devices
	
	
	
if (
$fh fopen('mtand.txt''r')) { 
	
	
	
	
while (!
feof($fh)) {
	
	
	
	
	
if (
fgets($fh)) {
	
	
	
	
	
	
$mtandcount++;
	
	
	
	
	
	
	
	
}
	
	
	
	
	
	
	
}
	
	
	
	
	
	
}
	
	
	
/* adding a print or echo line here will show that $mtandcount is increasing properly */
	
	
	
if (
$mtandcount <= 1) {
	
	

	
	
	
print 
"<font color=#000000><b> Note: There Is $mtandcount Device Stored In <font color=#E00000>$owner ($platform)<font color=#000000> Database (Refresh Page)</b><br>";
	
	
	
} else {
	
	
	
print 
"<font color=#000000><b> Note: There Are $mtandcount Devices Stored In <font color=#E00000>$owner ($platform)<font color=#000000> Database (Refresh Page)</b><br>";
	
	
	
	
	
}
	
	
	

	
	
	
	
}
	
	
	
}
	
	

	
//Figure out what choice was made so that data can be written to correct text file
	
if (
$platform=="iOS") {
	

	
	
 if (
$owner=="Mobile Team") { 
	
	
print 
"<font color=#6699FF><b> *Successfully Added Device To <font color=#E00000>$owner ($platform)<font color=#6699FF> Category!</b><br>";

	
	
	
//write the data to the file
	
	

	
	
	
fwrite($fh$data);
	
	
	

	
	
	
//counter for devices
	
	
	
if (
$fh fopen('mtios.txt''r')) { 
	
	
	
	
while (!
feof($fh)) {
	
	
	
	
	
if (
fgets($fh)) {
	
	
	
	
	
	
$mtioscount++;
	
	
	
	
	
	
	
	
}
	
	
	
	
	
	
	
}
	
	
	
	
	
	
}
	
	
	
/* adding a print or echo line here will show that $mtioscount is increasing properly */
	
	
	
if (
$mtioscount <= 1) {
	
	

	
	
	
print 
"<font color=#000000><b> Note: There Is $mtioscount Device Stored In <font color=#E00000>$owner ($platform)<font color=#000000> Database (Refresh Page)</b><br>";
	
	
	
} else {
	
	
	
print 
"<font color=#000000><b> Note: There Are $mtioscount Devices Stored In <font color=#E00000>$owner ($platform)<font color=#000000> Database (Refresh Page)</b><br>";
	
	
	
	
	
}
	
	
	

	
	
	
	
}
	
	
	
}

	
//Figure out what choice was made so that data can be written to correct text file
	
if (
$platform=="MISC") {
	

	
	
 if (
$owner=="Mobile Team") { 
	
	
print 
"<font color=#6699FF><b> *Successfully Added Device To <font color=#E00000>$owner ($platform)<font color=#6699FF> Category!</b><br>";

	
	
	
//write the data to the file
	
	

	
	
	
fwrite($fh$data);
	
	
	

	
	
	
//counter for devices
	
	
	
if (
$fh fopen('mtmisc.txt''r')) { 
	
	
	
	
while (!
feof($fh)) {
	
	
	
	
	
if (
fgets($fh)) {
	
	
	
	
	
	
$mtmisccount++;
	
	
	
	
	
	
	
	
}
	
	
	
	
	
	
	
}
	
	
	
	
	
	
}
	
	
	
/* adding a print or echo line here will show that $mtmisccount is increasing properly */
	
	
	
if (
$mtmisccount <= 1) {
	
	

	
	
	
print 
"<font color=#000000><b> Note: There Is $mtmisccount Device Stored In <font color=#E00000>$owner ($platform)<font color=#000000> Database (Refresh Page)</b><br>";
	
	
	
} else {
	
	
	
print 
"<font color=#000000><b> Note: There Are $mtmisccount Devices Stored In <font color=#E00000>$owner ($platform)<font color=#000000> Database (Refresh Page)</b><br>";
	
	
	
	
	
}
	
	
	

	
	
	
	
}
	
	
	
}

	
//Figure out what choice was made so that data can be written to correct text file
	
if (
$platform=="Android") {
	

	
	
 if (
$owner=="Biz Dev") { 
	
	
print 
"<font color=#6699FF><b> *Successfully Added Device To <font color=#E00000>$owner ($platform)<font color=#6699FF> Category!</b><br>";

	
	
	
//write the data to the file
	
	

	
	
	
fwrite($fh$data);
	
	
	

	
	
	
//counter for devices
	
	
	
if (
$fh fopen('bdand.txt''r')) { 
	
	
	
	
while (!
feof($fh)) {
	
	
	
	
	
if (
fgets($fh)) {
	
	
	
	
	
	
$bdandcount++;
	
	
	
	
	
	
	
	
}
	
	
	
	
	
	
	
}
	
	
	
	
	
	
}
	
	
	
/* adding a print or echo line here will show that $bdandcount is increasing properly */
	
	
	
if (
$bdandcount <= 1) {
	
	

	
	
	
print 
"<font color=#000000><b> Note: There Is $bdandcount Device Stored In <font color=#E00000>$owner ($platform)<font color=#000000> Database (Refresh Page)</b><br>";
	
	
	
} else {
	
	
	
print 
"<font color=#000000><b> Note: There Are $bdandcount Devices Stored In <font color=#E00000>$owner ($platform)<font color=#000000> Database (Refresh Page)</b><br>";
	
	
	
	
	
}
	
	
	

	
	
	
	
}
	
	
	
}

	
//Figure out what choice was made so that data can be written to correct text file
	
if (
$platform=="iOS") {
	

	
	
 if (
$owner=="Biz Dev") { 
	
	
print 
"<font color=#6699FF><b> *Successfully Added Device To <font color=#E00000>$owner ($platform)<font color=#6699FF> Category!</b><br>";

	
	
	
//write the data to the file
	
	

	
	
	
fwrite($fh$data);
	
	
	

	
	
	
//counter for devices
	
	
	
if (
$fh fopen('bdios.txt''r')) { 
	
	
	
	
while (!
feof($fh)) {
	
	
	
	
	
if (
fgets($fh)) {
	
	
	
	
	
	
$bdioscount++;
	
	
	
	
	
	
	
	
}
	
	
	
	
	
	
	
}
	
	
	
	
	
	
}
	
	
	
/* adding a print or echo line here will show that $bdioscount is increasing properly */
	
	
	
if (
$bdioscount <= 1) {
	
	

	
	
	
print 
"<font color=#000000><b> Note: There Is $bdioscount Device Stored In <font color=#E00000>$owner ($platform)<font color=#000000> Database (Refresh Page)</b><br>";
	
	
	
} else {
	
	
	
print 
"<font color=#000000><b> Note: There Are $bdioscount Devices Stored In <font color=#E00000>$owner ($platform)<font color=#000000> Database (Refresh Page)</b><br>";
	
	
	
	
	
}
	
	
	

	
	
	
	
}
	
	
	
}

	
//Figure out what choice was made so that data can be written to correct text file
	
if (
$platform=="MISC") {
	

	
	
 if (
$owner=="Biz Dev") { 
	
	
print 
"<font color=#6699FF><b> *Successfully Added Device To <font color=#E00000>$owner ($platform)<font color=#6699FF> Category!</b><br>";

	
	
	
//write the data to the file
	
	

	
	
	
fwrite($fh$data);
	
	
	

	
	
	
//counter for devices
	
	
	
if (
$fh fopen('bdmisc.txt''r')) { 
	
	
	
	
while (!
feof($fh)) {
	
	
	
	
	
if (
fgets($fh)) {
	
	
	
	
	
	
$bdmisccount++;
	
	
	
	
	
	
	
	
}
	
	
	
	
	
	
	
}
	
	
	
	
	
	
}
	
	
	
/* adding a print or echo line here will show that $bdmisccount is increasing properly */
	
	
	
if (
$bdmisccount <= 1) {
	
	

	
	
	
print 
"<font color=#000000><b> Note: There Is $bdmisccount Device Stored In <font color=#E00000>$owner ($platform)<font color=#000000> Database (Refresh Page)</b><br>";
	
	
	
} else {
	
	
	
print 
"<font color=#000000><b> Note: There Are $bdmisccount Devices Stored In <font color=#E00000>$owner ($platform)<font color=#000000> Database (Refresh Page)</b><br>";
	
	
	
	
	
}
	
	
	

	
	
	
	
}
	
	
	
}

	
//close the file
	
	

	
fclose($fh);
	
     

	
unset (
$_SESSION["FORM_SECRET"]);

	
	
	
}
	
	
}

	
}
	
 
?>

	

	
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	

	
<style type="text/css">
	
	

	
	
body{
	
	
	

	
	
	
font: 10px Verdana, Arial, Helvetica, sans-serif;
	
	

	
	
}
	

	
</style>


<?php 

	
$output ''//defining variable before use

if($output!=""){ echo $output; } 

$secret=md5(uniqid(rand(), true)); //generate a random value
$_SESSION['FORM_SECRET'] = $secret//set the session

?>

<form action = "<? echo $_SERVER['PHP_SELF']?>" method = "post">
	
<div style="border:2px solid #cccccc;margin:8px;padding:8px;width:600px;">
	

	
<table width="80%">
	

	
<tr><td><b>Enter Device Name: </b></td><td><input name="name" type="text" style="width:200px;" /></td></tr>
	
<tr><td><b>Enter MDN: </b></td><td><input name="mdn" type="text" style="width:200px;" /></td></tr>
	
<tr><td><b>Enter Carrier: </b></td><td><input name="carrier" type="text" style="width:200px;" /></td></tr>
	
<tr><td><b>Enter MEID/IMEI: </b></td><td><input name="meid" type="text" style="width:200px;" /></td></tr>
	
<tr><td><b>Enter OS Version: </b></td><td><input name="version" type="text" style="width:200px;" /></td></tr>
	
<tr><td><b>Enter Received Date: </b></td><td><input name="date" type="text" style="width:200px;" /></td></tr>
	
<tr><td><b>Enter Notes: </b></td><td><input name="notes" type="text" style="width:200px;" /></td></tr>
	

	
<tr><td><b>Is Voice Enabled (Yes/No):</b></td><td>
	
	

	
<select name="voice" style="width:200px;"> 
	

	
<option>Yes</option>
	

	
<option>No</option>
	
	

	
</select></td></tr>

	
<tr><td><b>Select Device Platform (Android/iOS/MISC):</b></td><td>
	
	

	
<select name="platform" style="width:200px;"> 
	

	
<option>Android</option>
	

	
<option>iOS</option>
	
<option>MISC</option>
	
	

	
</select></td></tr>

	
<tr><td><b>Select Device Owner (Mobile Team/Biz Dev):</b></td><td>
	
	

	
<select name="owner" style="width:200px;"> 
	

	
<option>Mobile Team</option>
	

	
<option>Biz Dev</option>
	
	

	
</select></td></tr>
	

	
</table>
	


	
<!-- echo the contents of hiddle field, FORM_SECRET, into the variable $_SESSION --> 
	
<input type="hidden" name="form_secret" id="form_secret" value="<?php echo $_SESSION['FORM_SECRET'];?>" />
	
<input type="submit" name="submit" value="Update" />
	
</div>
</form>
	


	
</tr>
	
</table>
        </ul>
    </li>
</ul>
</div>

   

</body>

</html>

ErnieAlex

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 1847
  • Karma: 32
    • View Profile
Re: Forms PHP + Javascript Help
« Reply #22 on: June 11, 2012, 12:43:11 PM »
Well, I have been gone a lot lately.  Just noticed you posted the next area of code issues...

The only main issue I see at first glance is your error messages.  You test to see if 'name', 'mdn' etc is empty.
But, you give out the same error for each.  You should change them to say something like:
   if (empty($name)) {
     print "<font color=#E00000><b> *Error: Must Fill Out All Fields! Name missing! Information Not Stored</b><br>"; }
   elseif (empty($mdn)) {
      print "<font color=#E00000><b> *Error: Must Fill Out All Fields! MDN missing! Information Not Stored</b><br>"; }

Something simple like adding the field name makes it much easier for the user to understand where
they went wrong.

As far as "deleting" records, that is not too hard to do.  Using MySQL, it would be a simple query something
like $query="DELETE * FROM table-name WHERE item-number=$_GET['delete-number'];  Then run query.
(general terms not exact!)   But, for text files it would be a little tricky.  First, the delete code would be done
server-side because it is PHP.  There are two easy ways to do this.  Once the DELETE button has been pressed,
you can either rewrite the entire file with the current data.  I think that is what you are doing now.  Or, you can
remove the data from the current text file by locating it's location and editing out that line of data.  For your
current program, it is simpler just to rewrite the entire file. 

So, basically, you would just save the file skipping the line of data that you want to delete.  The save routines
are already in your code because you write the data to the file and then re-read it back in to display the new
version.  You just need to check for the deleted item and re-save the file and re-read the file to display it again.

Hope that made sense!   Now, what exactly can we help you with.  I think you are nearly complete on this
project.  Try to think out your re-saving without the deleted item and post the entire file again when you get
stuck on it.   Good luck!

phpBeginner1

  • New Member
  • *
  • Posts: 20
  • Karma: 0
    • View Profile
Re: Forms PHP + Javascript Help
« Reply #23 on: June 12, 2012, 08:45:31 PM »
Yes, that makes sense and I am trying to do what you are saying. I can add items to my file, and delete it. But I am using a link as the action that initiates the delete entry. It is not working correctly. I need more direct help on this. Copy and paste my code into one single text file, sandbox the file, and test it out. You will see what I mean. Add 1 item, refresh the page, click on the Delete text and my issue will come to light. I am being led to a page with added =?delete=0 at the end of the URL. That is not my real page. I don't know how to fix, I have tried independantly for a while. Anyone with suggestions?

phpBeginner1

  • New Member
  • *
  • Posts: 20
  • Karma: 0
    • View Profile
Re: Forms PHP + Javascript Help
« Reply #24 on: June 12, 2012, 08:48:10 PM »
Part 1 Code (Copy and paste into one text file). Name your text file as "indexNew"

Code: [Select]
<?php
session_start
(); //start a session

error_reporting(E_ALL); //E_ALL ^ E_NOTICE
ini_set('display_errors','1'); //Initialize custom debugging function
?>


<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Device Manager</title>

<!-- Call JQuery -->
<script src="http://www.acmeous.com/tutorials/demo/acmeousCollapsibleLists/acmeousCollapsibleLists.js"
type="text/javascript"></script>


<!-- Setup Event Listener -->
<script type="text/javascript"><!--
if (window.addEventListener) {
window.addEventListener("load", function(){makeCollapsible(document.getElementById('addDevice'), 0);}, false);
} else if (window.attachEvent) {
window.attachEvent("onload", function(){makeCollapsible(document.getElementById('addDevice'), 1);});
} else {
window.onload = function(){makeCollapsible(document.getElementById('addDevice'), 1);};
}
-->
</script>

</head>

<body>

<?php

print "<font size='6'>DEVICE INVENTORY (Android): MOBILE TEAM</font><br>";

$textfile 'mtand.txt';
$data ''//defining variable before use

      
if (file_exists($textfile) && is_readable($textfile))      
      {         
         
$file file($textfile);      

         foreach (
$file as $line)
         {
            
//separate each element and store in temp array.      
            
$tmp explode(":"$line);               

            
//assign each element to array.        
            
$data[] = 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 ($data!=""){
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 ($data 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>";

$return "indexNew2.htm";
$delete = @$_GET['delete']; 
$textFile file("mtand.txt"); 
$lines count($textFile); 

if(
$delete != "" && $delete >! $lines || $delete === '0') { 
    
$textFile[$delete] = ""
    
$fileUpdate fopen("mtand.txt""wb"); 
    for(
$a=0$a<$lines$a++) { 
           
fwrite($fileUpdate$textFile[$a]); 
    } 
    
fclose($fileUpdate); 
   
header("location:$return"); 
   exit; 


foreach(
$textFile as $key => $val) { 
$line ="<a href =?delete=$key>[ DELETE ]</a><br/>";

echo 
$line;       

?>


<?php

print "<font size='6'>DEVICE INVENTORY (iOS): MOBILE TEAM</font><br>";

$textfile 'mtios.txt';
$data ''//defining variable before use

      
if (file_exists($textfile) && is_readable($textfile))      
      {         
         
$file file($textfile);      

         foreach (
$file as $line)
         {
            
//separate each element and store in temp array.      
            
$tmp explode(":"$line);               

            
//assign each element to array.        
            
$data[] = 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 ($data!=""){
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 ($data 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>";
?>


<?php

print "<font size='6'>DEVICE INVENTORY (MISC): MOBILE TEAM</font><br>";

$textfile 'mtmisc.txt';
$data ''//defining variable before use

      
if (file_exists($textfile) && is_readable($textfile))      
      {         
         
$file file($textfile);      

         foreach (
$file as $line)
         {
            
//separate each element and store in temp array.      
            
$tmp explode(":"$line);               

            
//assign each element to array.        
            
$data[] = 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 ($data!=""){
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 ($data 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>";
?>


<?php

print "<font size='6'>DEVICE INVENTORY (Android): BIZ DEV</font><br>";

$textfile 'bdand.txt';
$data ''//defining variable before use

      
if (file_exists($textfile) && is_readable($textfile))      
      {         
         
$file file($textfile);      

         foreach (
$file as $line)
         {
            
//separate each element and store in temp array.      
            
$tmp explode(":"$line);               

            
//assign each element to array.        
            
$data[] = 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 ($data!=""){
echo "<tr><th style='background:#A6A6A6'>Device Name</th><th style='background:#A6A6A6'>MDN</th><th style='background:#A6A6A6'>Carrier</th><th style='background:#A6A6A6'>MEID/IMEI</th><th style='background:#A6A6A6'>OS Version</th><th style='background:#A6A6A6'>Received Date</th><th style='background:#A6A6A6'>Notes</th><th style='background:#A6A6A6'>Voice</th></tr>";
foreach ($data 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>";
?>


<?php

print "<font size='6'>DEVICE INVENTORY (iOS): BIZ DEV</font><br>";

$textfile 'bdios.txt';
$data ''//defining variable before use

      
if (file_exists($textfile) && is_readable($textfile))      
      {         
         
$file file($textfile);      

         foreach (
$file as $line)
         {
            
//separate each element and store in temp array.      
            
$tmp explode(":"$line);               

            
//assign each element to array.        
            
$data[] = 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 ($data!=""){
echo "<tr><th style='background:#A6A6A6'>Device Name</th><th style='background:#A6A6A6'>MDN</th><th style='background:#A6A6A6'>Carrier</th><th style='background:#A6A6A6'>MEID/IMEI</th><th style='background:#A6A6A6'>OS Version</th><th style='background:#A6A6A6'>Received Date</th><th style='background:#A6A6A6'>Notes</th><th style='background:#A6A6A6'>Voice</th></tr>";
foreach ($data 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>";
?>


<?php

print "<font size='6'>DEVICE INVENTORY (MISC): BIZ DEV</font><br>";

$textfile 'bdmisc.txt';
$data ''//defining variable before use

      
if (file_exists($textfile) && is_readable($textfile))      
      {         
         
$file file($textfile);      

         foreach (
$file as $line)
         {
            
//separate each element and store in temp array.      
            
$tmp explode(":"$line);               

            
//assign each element to array.        
            
$data[] = 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 ($data!=""){
echo "<tr><th style='background:#A6A6A6'>Device Name</th><th style='background:#A6A6A6'>MDN</th><th style='background:#A6A6A6'>Carrier</th><th style='background:#A6A6A6'>MEID/IMEI</th><th style='background:#A6A6A6'>OS Version</th><th style='background:#A6A6A6'>Received Date</th><th style='background:#A6A6A6'>Notes</th><th style='background:#A6A6A6'>Voice</th></tr>";
foreach ($data 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>";
?>

Pay close attention to (WARNING: Don't recopy this part)
Code: [Select]
$return = "indexNew2.htm";
$delete = @$_GET['delete'];
$textFile = file("mtand.txt");
$lines = count($textFile);

if($delete != "" && $delete >! $lines || $delete === '0') {
    $textFile[$delete] = "";
    $fileUpdate = fopen("mtand.txt", "wb");
    for($a=0; $a<$lines; $a++) {
           fwrite($fileUpdate, $textFile[$a]);
    }
    fclose($fileUpdate);
   header("location:$return");
   exit;

That is where my mistake is, I know.


phpBeginner1

  • New Member
  • *
  • Posts: 20
  • Karma: 0
    • View Profile
Re: Forms PHP + Javascript Help
« Reply #25 on: June 12, 2012, 08:48:57 PM »
Code Part Two. Copy the rest of the code in the same file, underneath the first half.

Code: [Select]
<?php

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

$platform$_POST['platform']; //defining variable before use
$owner$_POST['owner']; //defining variable before use

if ($platform=="Android") {
if ($owner=="Mobile Team") {
//prepare 'mtand.txt' file for data
$fh fopen("mtand.txt","a+") or die("File Close"); }
}

if ($platform=="iOS") {
if ($owner=="Mobile Team") {
//prepare 'mtios.txt' file for data
$fh fopen("mtios.txt","a+") or die("File Close"); }
}

if ($platform=="MISC") {
if ($owner=="Mobile Team") {
//prepare 'mtmisc.txt' file for data
$fh fopen("mtmisc.txt","a+") or die("File Close"); }
}

if ($platform=="Android") {
if ($owner=="Biz Dev") {
//prepare 'bdand.txt' file for data
$fh fopen("bdand.txt","a+") or die("File Close"); }
}

if ($platform=="iOS") {
if ($owner=="Biz Dev") {
//prepare 'bdios.txt' file for data
$fh fopen("bdios.txt","a+") or die("File Close"); }
}

if ($platform=="MISC") {
if ($owner=="Biz Dev") {
//prepare 'bdmisc.txt' file for data
$fh fopen("bdmisc.txt","a+") or die("File Close"); }
}


$name$_POST['name'];
$mdn$_POST['mdn'];
$carrier$_POST['carrier'];
$meid$_POST['meid'];
$version$_POST['version'];
$date$_POST['date'];
$notes$_POST['notes'];
$voice$_POST['voice'];

/* $platform= $_POST['platform'] */
/* $owner= $_POST['owner'] */

//setup implementation rules for notes
$notes=stripslashes($notes);

//implement validation
if (empty($name)) {
print "<font color=#E00000><b> *Error: Must Fill Out All Fields! Mobile Device Information Not Stored</b><br>"; }
elseif (empty($mdn)) {
print "<font color=#E00000><b> *Error: Must Fill Out All Fields! Mobile Device Information Not Stored</b><br>"; }
elseif (empty($carrier)) {
print "<font color=#E00000><b> *Error: Must Fill Out All Fields! Mobile Device Information Not Stored</b><br>"; }
elseif (empty($meid)) {
print "<font color=#E00000><b> *Error: Must Fill Out All Fields! Mobile Device Information Not Stored</b><br>"; }
elseif (empty($version)) {
print "<font color=#E00000><b> *Error: Must Fill Out All Fields! Mobile Device Information Not Stored</b><br>"; }
elseif (empty($date)) {
print "<font color=#E00000><b> *Error: Must Fill Out All Fields! Mobile Device Information Not Stored</b><br>"; }

else {

//Retrieve the value of the hidden field
$form_secret $_POST['form_secret']; /* isset($_POST["form_secret"])?$_POST["form_secret"]:''; */

if(isset($_SESSION['FORM_SECRET'])) {
if(strcasecmp($form_secret$_SESSION['FORM_SECRET']) === 0) { /* if($_POST['secret'] == $_SESSION['secret']) { */

$mtandcount '';
$mtioscount '';
$mtmisccount '';
$bdandcount '';
$bdioscount '';
$bdmisccount '';

//assemble the data into a line variable
$data$name ":" $mdn ":" $carrier ":" $meid ":" $version ":" $date ":" $notes ":" $voice ":" "\r\n";

//Figure out what choice was made so that data can be written to correct text file
if ($platform=="Android") {
 if ($owner=="Mobile Team") { 
print "<font color=#6699FF><b> *Successfully Added Device To <font color=#E00000>$owner ($platform)<font color=#6699FF> Category!</b><br>";

//write the data to the file
fwrite($fh$data);

//counter for devices
if ($fh fopen('mtand.txt''r')) { 
while (!feof($fh)) {
if (fgets($fh)) {
$mtandcount++;
}
}
}
/* adding a print or echo line here will show that $mtandcount is increasing properly */
if ($mtandcount <= 1) {
print "<font color=#000000><b> Note: There Is $mtandcount Device Stored In <font color=#E00000>$owner ($platform)<font color=#000000> Database (Refresh Page)</b><br>";
} else {
print "<font color=#000000><b> Note: There Are $mtandcount Devices Stored In <font color=#E00000>$owner ($platform)<font color=#000000> Database (Refresh Page)</b><br>";
}
}
}

//Figure out what choice was made so that data can be written to correct text file
if ($platform=="iOS") {
 if ($owner=="Mobile Team") { 
print "<font color=#6699FF><b> *Successfully Added Device To <font color=#E00000>$owner ($platform)<font color=#6699FF> Category!</b><br>";

//write the data to the file
fwrite($fh$data);

//counter for devices
if ($fh fopen('mtios.txt''r')) { 
while (!feof($fh)) {
if (fgets($fh)) {
$mtioscount++;
}
}
}
/* adding a print or echo line here will show that $mtioscount is increasing properly */
if ($mtioscount <= 1) {
print "<font color=#000000><b> Note: There Is $mtioscount Device Stored In <font color=#E00000>$owner ($platform)<font color=#000000> Database (Refresh Page)</b><br>";
} else {
print "<font color=#000000><b> Note: There Are $mtioscount Devices Stored In <font color=#E00000>$owner ($platform)<font color=#000000> Database (Refresh Page)</b><br>";
}
}
}

//Figure out what choice was made so that data can be written to correct text file
if ($platform=="MISC") {
 if ($owner=="Mobile Team") { 
print "<font color=#6699FF><b> *Successfully Added Device To <font color=#E00000>$owner ($platform)<font color=#6699FF> Category!</b><br>";

//write the data to the file
fwrite($fh$data);

//counter for devices
if ($fh fopen('mtmisc.txt''r')) { 
while (!feof($fh)) {
if (fgets($fh)) {
$mtmisccount++;
}
}
}
/* adding a print or echo line here will show that $mtmisccount is increasing properly */
if ($mtmisccount <= 1) {
print "<font color=#000000><b> Note: There Is $mtmisccount Device Stored In <font color=#E00000>$owner ($platform)<font color=#000000> Database (Refresh Page)</b><br>";
} else {
print "<font color=#000000><b> Note: There Are $mtmisccount Devices Stored In <font color=#E00000>$owner ($platform)<font color=#000000> Database (Refresh Page)</b><br>";
}
}
}

//Figure out what choice was made so that data can be written to correct text file
if ($platform=="Android") {
 if ($owner=="Biz Dev") { 
print "<font color=#6699FF><b> *Successfully Added Device To <font color=#E00000>$owner ($platform)<font color=#6699FF> Category!</b><br>";

//write the data to the file
fwrite($fh$data);

//counter for devices
if ($fh fopen('bdand.txt''r')) { 
while (!feof($fh)) {
if (fgets($fh)) {
$bdandcount++;
}
}
}
/* adding a print or echo line here will show that $bdandcount is increasing properly */
if ($bdandcount <= 1) {
print "<font color=#000000><b> Note: There Is $bdandcount Device Stored In <font color=#E00000>$owner ($platform)<font color=#000000> Database (Refresh Page)</b><br>";
} else {
print "<font color=#000000><b> Note: There Are $bdandcount Devices Stored In <font color=#E00000>$owner ($platform)<font color=#000000> Database (Refresh Page)</b><br>";
}
}
}

//Figure out what choice was made so that data can be written to correct text file
if ($platform=="iOS") {
 if ($owner=="Biz Dev") { 
print "<font color=#6699FF><b> *Successfully Added Device To <font color=#E00000>$owner ($platform)<font color=#6699FF> Category!</b><br>";

//write the data to the file
fwrite($fh$data);

//counter for devices
if ($fh fopen('bdios.txt''r')) { 
while (!feof($fh)) {
if (fgets($fh)) {
$bdioscount++;
}
}
}
/* adding a print or echo line here will show that $bdioscount is increasing properly */
if ($bdioscount <= 1) {
print "<font color=#000000><b> Note: There Is $bdioscount Device Stored In <font color=#E00000>$owner ($platform)<font color=#000000> Database (Refresh Page)</b><br>";
} else {
print "<font color=#000000><b> Note: There Are $bdioscount Devices Stored In <font color=#E00000>$owner ($platform)<font color=#000000> Database (Refresh Page)</b><br>";
}
}
}

//Figure out what choice was made so that data can be written to correct text file
if ($platform=="MISC") {
 if ($owner=="Biz Dev") { 
print "<font color=#6699FF><b> *Successfully Added Device To <font color=#E00000>$owner ($platform)<font color=#6699FF> Category!</b><br>";

//write the data to the file
fwrite($fh$data);

//counter for devices
if ($fh fopen('bdmisc.txt''r')) { 
while (!feof($fh)) {
if (fgets($fh)) {
$bdmisccount++;
}
}
}
/* adding a print or echo line here will show that $bdmisccount is increasing properly */
if ($bdmisccount <= 1) {
print "<font color=#000000><b> Note: There Is $bdmisccount Device Stored In <font color=#E00000>$owner ($platform)<font color=#000000> Database (Refresh Page)</b><br>";
} else {
print "<font color=#000000><b> Note: There Are $bdmisccount Devices Stored In <font color=#E00000>$owner ($platform)<font color=#000000> Database (Refresh Page)</b><br>";
}
}
}

//close the file
fclose($fh);      

unset ($_SESSION["FORM_SECRET"]);

}
}

}
 
?>



<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body{
font: 10px Verdana, Arial, Helvetica, sans-serif;
}
</style>


<?php 

$output ''//defining variable before use

if($output!=""){ echo $output; } 

$secret=md5(uniqid(rand(), true)); //generate a random value
$_SESSION['FORM_SECRET'] = $secret//set the session

?>


<form action = "<? echo $_SERVER['PHP_SELF']?>" method = "post">
<div style="border:2px solid #cccccc;margin:8px;padding:8px;width:600px;">
<table width="80%">
<tr><td><b>Enter Device Name: </b></td><td><input name="name" type="text" style="width:200px;" /></td></tr>
<tr><td><b>Enter MDN: </b></td><td><input name="mdn" type="text" style="width:200px;" /></td></tr>
<tr><td><b>Enter Carrier: </b></td><td><input name="carrier" type="text" style="width:200px;" /></td></tr>
<tr><td><b>Enter MEID/IMEI: </b></td><td><input name="meid" type="text" style="width:200px;" /></td></tr>
<tr><td><b>Enter OS Version: </b></td><td><input name="version" type="text" style="width:200px;" /></td></tr>
<tr><td><b>Enter Received Date: </b></td><td><input name="date" type="text" style="width:200px;" /></td></tr>
<tr><td><b>Enter Notes: </b></td><td><input name="notes" type="text" style="width:200px;" /></td></tr>
<tr><td><b>Is Voice Enabled (Yes/No):</b></td><td>
<select name="voice" style="width:200px;">
<option>Yes</option>
<option>No</option>
</select></td></tr>

<tr><td><b>Select Device Platform (Android/iOS/MISC):</b></td><td>
<select name="platform" style="width:200px;">
<option>Android</option>
<option>iOS</option>
<option>MISC</option>
</select></td></tr>

<tr><td><b>Select Device Owner (Mobile Team/Biz Dev):</b></td><td>
<select name="owner" style="width:200px;">
<option>Mobile Team</option>
<option>Biz Dev</option>
</select></td></tr>
</table>

<!-- echo the contents of hiddle field, FORM_SECRET, into the variable $_SESSION -->
<input type="hidden" name="form_secret" id="form_secret" value="<?php echo $_SESSION['FORM_SECRET'];?>" />
<input type="submit" name="submit" value="Update" />
</div>
</form>
</table>
</div>

   

</body>

</html>

phpBeginner1

  • New Member
  • *
  • Posts: 20
  • Karma: 0
    • View Profile
Re: Forms PHP + Javascript Help
« Reply #26 on: June 12, 2012, 08:55:16 PM »
Part 1 Code (Copy and paste into one text file). Name your text file as "indexNew"

Name your file "indexNew2.htm". Sorry, no edit of posts once sent. Now you will see what I see.

ErnieAlex

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 1847
  • Karma: 32
    • View Profile
Re: Forms PHP + Javascript Help
« Reply #27 on: June 16, 2012, 11:20:58 AM »
I will be available later today and will try to sort your error out. 

Sorry, I was busy with a sick family member.  Sorry for the delay...

At first look it is just the way you are trying to delete the item.  I think there is a better way, but, will have to test it later this afternoon.   More then...

ErnieAlex

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 1847
  • Karma: 32
    • View Profile
Re: Forms PHP + Javascript Help
« Reply #28 on: July 03, 2012, 03:56:46 PM »
Hello, sorry, I have been gone for so long.  Sick mother...

Did you get your code fixed up?  If not let me know what errors you are still sorting out...

If so, congrats...