TheJoey Posted August 26, 2009 Author Share Posted August 26, 2009 when i used them as a single string i got the error saying, that fwrite can only process 3 paramatters Quote Link to comment https://forums.phpfreaks.com/topic/171784-solved-html-forms-php/page/2/#findComment-906745 Share on other sites More sharing options...
Adam Posted August 26, 2009 Share Posted August 26, 2009 'join' / 'concatenate' the strings before using them with frwite... Quote Link to comment https://forums.phpfreaks.com/topic/171784-solved-html-forms-php/page/2/#findComment-906749 Share on other sites More sharing options...
TheJoey Posted August 26, 2009 Author Share Posted August 26, 2009 Sorry i guess i shouldnt of posted here. I dont know how do these things you ask off. Ill just do a little more reading i guess. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/171784-solved-html-forms-php/page/2/#findComment-906750 Share on other sites More sharing options...
Adam Posted August 26, 2009 Share Posted August 26, 2009 There are many ways you can join a string, probably the most simplest method being to concatenate several variables together, for example: $user_info = $fname . "\n" . $lname . "\n" . $email; //etc. It would depend how you want the information formatted in the text file though as to what you would join them together with. In the example I'm using "\n" which is a line break. So the data in the text file would end up being (with example data): John Smith jsmith@example.com You'd probably want either a double line break ("\n\n") or some form of delimiter to know 2 sets of data apart. The example I gave is, as I mentioned using line breaks, but you could also use other delimiters such as: $user_info = $fname . "||" . $lname . "||" . $email; //etc. Which would give you: John||Smith||jsmith@example.com You could then separate sets of data up with a line break or a different delimiter (e.g. "||||"). If you're feeling up to it though I'd suggest entering the user data into an array and using JSON or serialize, store the data in a more interchangeable format. Quote Link to comment https://forums.phpfreaks.com/topic/171784-solved-html-forms-php/page/2/#findComment-906767 Share on other sites More sharing options...
TheJoey Posted August 26, 2009 Author Share Posted August 26, 2009 Before i try your code i think i may have got it to work this way Only problem is that it doesnt the ELSE <?php error_reporting(E_ALL); ini_set('display_errors', '1'); if (isset($_POST['email'] , $_POST['fname'] , $_POST['lname'] , $_POST['age'] , $_POST['address'] , $_POST['city'])) { // some form of email validation $email = ($_POST['email']); $fname = ($_POST['fname']); $lname = ($_POST['lname']); $age = ($_POST['age']); $address = ($_POST['address']); $city = ($_POST['city']); // write-to file $filename = 'text.txt'; // attempt to open the file if ($handle = fopen($filename, 'a')) { // attempt to write to the file if (!fwrite ($handle, $email)); if (!fwrite ($handle, $fname)); if (!fwrite ($handle, $lname)); if (!fwrite ($handle, $age)); if (!fwrite ($handle, $address)); if (!fwrite ($handle, $city)); { echo 'Cannot write to file'; } else { echo 'Added to our System'; } } fclose($handle); } ?> Parse error: syntax error, unexpected T_ELSE in C:\xampplite\htdocs\part2\text1.php on line 37 its just a different way ive tried it, i am also working on the example u provided. Quote Link to comment https://forums.phpfreaks.com/topic/171784-solved-html-forms-php/page/2/#findComment-906784 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.