Sassy34 Posted November 23, 2009 Share Posted November 23, 2009 I made this form and I need it to read the data and write the data to a table and its not working can someone please help me and show me what I have wrong so I can fix it heres the html form I left off the doc type so it dont take up that much room <form> <h1>Telephone Directory</h1> <br> <table align='Left'> <tr> <td>LastName</td> <td><input name='LastName' /></td> </tr> <tr> <td>FirstName</td> <td><input name='FirstName' /></td> </tr> <tr> <td>StreetAddress</td> <td><input name='StreetAddress' /></td> </tr> <tr> <td>City</td> <td><input name='City' /></td> </tr> <tr> <td>State</td> <td><input name='State' /></td> </tr> <tr> <td>Zip</td> <td><input name='Zip' /></td> </tr> <tr> <td>AreaCode</td> <td><input name='AreaCode' /></td> </tr> <tr> <td>PhoneNumber</td> <td><input name='PhoneNumber' /></td> </tr> <tr> <td></td> <td><input type="submit" value="Submit" /></td> <td><a href="Telephonewrite.php">ReadFile</a></td> </tr> </table> </form> </body> </html> php.file to read <body> <h1>Telephone Directory</h1> <?php $fileHandle=fopen("read.txt","r"); readfile("read.txt"); $record=fgets($fileHandle); echo("<table><tr><td>FirstName</td><td>LastName</td><td>StreetAddress</td><td>City</td><td>State</td> <td>Zip</td><td>AreaCode</td><td>PhoneNumber</td></tr>"); while(!feof($fileHandle)) { $myArray=explode("|",$record); echo "<tr><td>$myArray[0]</td><td>$myArray[1]</td></tr>"; $record =fgets($fileHandle); $record =fgets($LastName); $record =fgets($FirstName); $record =fgets($StreetAddress); $record =fgets($City); $record =fgets($State); $record =fgets($Zip); $record =fgets($AreaCode); $record =fgets($PhoneNumber); } echo "</table>" ?> </body> </html> the php file to write <body> <h1>Telephone Directory</h1> <hr /> <?php if(isset($_GET['PhoneNumber']) && isset($_GET['LastName'])) { $LastName = $_GET['LastName']; $FirstName = $_GET['FirstName']; $StreetAdress = $_GET['StreetAddress']; $City = $_GET['City']; $State = $_GET['State']; $Zip = $_GET['Zip']; $AreaCode = $_GET['AreaCode']; $PhoneNumber = $_GET['PhoneNumber']; $record=$LastName. "|"; $record=$FirstName. "|"; $record .="\r\n"; $fileHandle = fopen("read.txt","a"); readfile("read.txt"); if(fwrite($read, $record)>0) echo "<p>your entry was successfully added to the file</p>"; else echo "<p>No data was written, please return to the form</p>"; fclose($fileHandle); } ?> <a href="Telephone.html">Form</a> </body> </html> Link to comment https://forums.phpfreaks.com/topic/182662-need-help-with-this-contact-form/ Share on other sites More sharing options...
Coreye Posted November 24, 2009 Share Posted November 24, 2009 What exactly isn't working about it? Link to comment https://forums.phpfreaks.com/topic/182662-need-help-with-this-contact-form/#findComment-964396 Share on other sites More sharing options...
Sassy34 Posted November 24, 2009 Author Share Posted November 24, 2009 Hi coeye, when I run it it wont show up on the txt file and if i click the extra link it dont show it in a table... Link to comment https://forums.phpfreaks.com/topic/182662-need-help-with-this-contact-form/#findComment-964510 Share on other sites More sharing options...
Deoctor Posted November 24, 2009 Share Posted November 24, 2009 hai i have modified your code some thing like this i think this should work <html> <head></head> <body> <form action='new.php' method='POST'> <!--Username: <input type='text' size='15' maxlength='25' name='fname'>--> <h1>Telephone Directory</h1> <br> <table align='Left'> <tr> <td>LastName</td> <td><input name='LastName' /></td> </tr> <tr> <td>FirstName</td> <td><input name='FirstName' /></td> </tr> <tr> <td>StreetAddress</td> <td><input name='StreetAddress' /></td> </tr> <tr> <td>City</td> <td><input name='City' /></td> </tr> <tr> <td>State</td> <td><input name='State' /></td> </tr> <tr> <td>Zip</td> <td><input name='Zip' /></td> </tr> <tr> <td>AreaCode</td> <td><input name='AreaCode' /></td> </tr> <tr> <td>PhoneNumber</td> <td><input name='PhoneNumber' /></td> </tr> <tr> <td></td> <td><input type="submit" /></td> <td></td> </tr> <td><a href="http://localhost/chaitu/testdir/111.txt">Read file</a></td> </table> </form> </body> </html> name it as use.html and the php file is <?php $lname=$_POST["LastName"]; $fname=$_POST["FirstName"]; $add=$_POST["StreetAddress"]; $file=fopen("111.txt","a+") or exit("Unable to open file!"); /*while(!feof($file)) { echo fgets($file)."<br/>"; }*/ fwrite($file,$lname); <br/> fwrite($file,$fname); <br/> fwrite($file,$add); <br/> fclose($file); echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=use.html\">"; ?> name this as new.php this would write the file and revert back to the use.html file.. now to display the file i have given the href link of the txt file.. u can use as fetch each line and display also I think this would resolve the issue Link to comment https://forums.phpfreaks.com/topic/182662-need-help-with-this-contact-form/#findComment-964548 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.