I'm learning how to take information from an html form and post the information into an aray. The ultimate goal is to write the data to a text file but I haven't been able to get the data from the form. I have a working example of an array in a php file to follow.
This is my working example:
HTML Code:<html> <head> <style type = "text/css"> h2 {color: orange; text-align: center;} body {background-color: cyan;} </style> <title>Array</title> </head> <body> <h2>Customer List</h2> <p> <? $userList = array("John" => array( "email" => "[email protected]", "website" => "www.john.com", "age" => "22", "password" => "pass") ); //if you just want to produce info about John you do this: foreach ($userList["John"] as $key=>$value) { echo "<b>(John)</b>$key - $value<br/>"; } ?> </body> </html>
I used this code to try to get the information from my form. I haven't been able to get it working though. I hit submit from the form and get a white screen. Can anyone see what I've done wrong? I've coded out the part about writing to a text file for now, until I know I can get the data from the form into the array.
HTML Code:<html> <head> <title>Storing Data</title> </head> <body> <h2>Array Storage</h2> <?php $user_list => array("user"=>array( 'fname'=> $_POST['fname'], 'email'=> $_POST['email'], 'website'=> $_POST['web'], 'age'=> $_POST['age'], 'password'=> $_POST['pass']) ); //$handle = fopen("storage.txt", "a+"); //foreach($user_list["user"] as $key=>$value){ //echo fwrite($handle, "<b>user<b/>$key - $value<br/>"; foreach ($user_list["user"] as $key=>$value) { echo "<b>user</b>$key - $value<br/>"; } //fclose($handle); ?> </body> </html>




Reply With Quote