Jump to content

NickWrenLab

New Members
  • Posts

    9
  • Joined

  • Last visited

NickWrenLab's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thank you so much for all the input! I will take all the advice, even though I am not an html coder, I do know C and C++ so the explanations were understood, and I will get working on the fixes to the form. I cannot thank you enough, I will eventually get the hang of php code now that I have gotten better code to look at and understand. What's the best way to get the hang of php code? and is there a good editor to use to tell you that a line wont work, or will give you a suggestion on what line of code you should use in different areas?
  2. Sorry I forgot I was testing this with an xlsx file for that index.php, but it should be $fp = fopen('WrenDB.csv', 'a+'); and I changed the action="index.php" to: <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="WrenForm" id="WrenForm">
  3. Hey, I should start off saying I have never written a script nor worked with server side code like php. That being said, I found examples all over the web, tried to find combinations of code till I finally just started from the basics and tried to write it myself, and somehow ended up getting a code that actually works. So I have a basic HTML form that needs to have all data from the form sent to a csv file. This works! Now I applied it to a much bigger form that I wrote html code for, but I am having problems applying the php code. It needs some work for the checkboxes; header(sending it to a url it doesnt do it); writing it to a csv file; Validating the first, last, email, age, before submitting; how to not move on if those aren't there. but the rest are fine being blank at times. radios also when checked by accident can't be unchecked or go to our open text boxes to write their "other" possible treatment I cant upload the csv's but they are simple, just having the heading of each section. basicform.php fputcsv.php index.php list of values and ids.txt
  4. So if I made the file with headers how can I get the data to keep appending? is that how hansford wrote the code?
  5. I changed used the code: <html> <head> </head> <body> <form name="form" method="post" action="<?=$_SERVER['PHP_SELF'];?>"> Name: <input type="text" name="fname" /> <br /> Surname: <input type="text" name="lname" /> <br /> Home: <input type="text" name="sex" /> <br /> <input type="submit" name="submit" /> </form> </body> <?php $_POST['fname'] = 'Sam'; $_POST['lname'] = 'Smith'; $_POST['sex'] = 'M'; $list = array( array( $_POST['fname'], $_POST['lname'], $_POST['sex'] ) ); $fp = fopen('test.csv', 'a'); foreach ($list as $fields) { fputcsv($fp, $fields); } fclose($fp); ?> </html> Hopefully all the code is working correctly, but as you said I might not have permission, which is something that I didnt think would be a problem. Would you know how to give access to let the fields be populated
  6. I changed the 'fputcsv' code for the 'file_put_contents' however nothing is writing to my test.csv file. the part I changed looks like this: //generate output for text file $csvData = $lastname . "\t" . $firstname . "\t" . $sex . "\t" . $box1 . "\t" . $box2 . "\n" ; //open file for output $handle = fopen('test.csv', 'a'); $csvData = "\\r\ ".implode ($del, $csvData); //write to the file foreach($csvData as $fields){ fputcsv($handle, $fields); } fclose($handler); } ?> And... Uh yea thats how I got the code that I have, aka googled it. Most of the sites I have looked up, downloaded or copied their code; tried to make changes or just took it as is and most dont work; or use and SQL database, which I am trying to prevent.
  7. I added in some php code that I have been trying to get to write to a csv file. However I still cannot get it to write to a file, I have tried the code file_put_contents('test.csv', $fields, FILE_APPEND); I've tried the normal fwrite and fputcsv but netiher worked fwrite($fp, $csvData) foreach($csvData as $fields){ fputcsv($fp, $fields); } <!DOCTYPE html> <html lang="en"> <head> <?php if (isset($_POST['Sumbit'])) { $filename = "/test.csv"; header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename=test.csv'); //read data from form $del = "\ "; $lastname = $_POST['lastname']; $firstname = $_POST['firstname']; $sex = $_POST['sex']; $box1 = $_POST['box1']; $box2 = $_POST['box2']; //generate output for text file $csvData = $lastname . "\t" . $firstname . "\t" . $sex . "\t" . $box1 . "\t" . $box2 . "\n" ; //open file for output $fp = fopen("/test.csv", "a"); $csvData = "\\r\ ".implode ($del, $csvData); //write to the file foreach($csvData as $fields){ file_put_contents('test.csv', $fields, FILE_APPEND); } fclose($fp); } ?> </head> <body> <form name="PatientForm" action="addContactCSV.php" method="post"> First name:<br> <input type="text" name="firstname"> <br> Last name:<br> <input type="text" name="lastname"> <br><br> <input type="radio" name="sex" value="male" checked> Male <br> <input type="radio" name="sex" value="female"> Female <br><br> <input type="checkbox" name="box1" value="1"> #1 option <br> <input type="checkbox" name="box2" value="2"> #2 option <br><br> <input type="submit" name="Submit" id="Submit" value="Submit" /> <input type="reset" name="Reset" id="button" value="Reset" /> </form> </body> </html>
  8. I need help with a php code that can take the information from a filled out html form and send the info to a csv file in the background (or on the host site). Taking a basic form as provided and the function $_POST how can I write code that will take the input data and export it to a file. If you can provide just a basic example of how a csv file is filled out or called upon using other scripts would really be appreciated. I saw this posted however didnt really help me out, however I am looking at one of the links posted at the bottom for PHP codeacdemy help. http://forums.phpfreaks.com/topic/298539-how-to-create-a-actionphp-page-for-html-form/ Also found that I could use this code to start the php, I just dont know how to apply it: <?php header("content-type: text/csv"); ?> HTML Form code: <html> <head> </head> <body> <form action="basicform.php"> First name:<br> <input type="text" name="firstname"> <br> Last name:<br> <input type="text" name="lastname"> <br><br> <input type="radio" name="sex" value="male" checked> Male <br> <input type="radio" name="sex" value="female"> Female <br><br> <input type="checkbox" name="box1" value="1"> #1 option <br> <input type="checkbox" name="box2" value="2"> #2 option <br><br> <input type="submit" value="Submit"> </form> </body> </html>
×
×
  • 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.