pepperface Posted October 30, 2007 Author Share Posted October 30, 2007 So, so near! The string now shows: name1 = Jane&name2 = Bobby&name3 = Tommy&name4 = Harry&name5 = Suzie Which means all that's left to do is to edit out the gaps in between the equals symbols... I'm right on it... back in a tick... Quote Link to comment https://forums.phpfreaks.com/topic/75327-simple-problem/page/2/#findComment-381290 Share on other sites More sharing options...
pepperface Posted October 30, 2007 Author Share Posted October 30, 2007 SUCCESS! SUCCESS!!! Oh, I really cannot BEGIN to thank you Adam!!! You're an absolute genius and a kind one, too! The time and effort you've put into this has helped me beyond measure and has, unquestionably, saved my sanity!!! I shall be eternally grateful... and if you're really lucky (sic) I'll post up later and bore you with the end result that it was all needed for in the first place. Hahaha Thanks!!! Quote Link to comment https://forums.phpfreaks.com/topic/75327-simple-problem/page/2/#findComment-381298 Share on other sites More sharing options...
pepperface Posted October 30, 2007 Author Share Posted October 30, 2007 Damn, damn, damn... spoke too soon. Unfortunately it transpires that all the current stuff does is re-write what's been included in the php in the first place. i.e. if the string says: $name1 = "name1=Jane&"; then it returns name1=Jane& However, the names are only there as a guideline. What I need is for users to be able to type in their own names. So, I went to modify the code, thus: $name1 = ""; in the hope that when the blank field was written to by a user it would display their name. Sadly, though, it's not a goer. Genuinely have to give up now, utterly defeated and very near to breaking down. So sorry for all the time you've spent on this - it just doesn't look like it's achievable but thank you very much indeed for trying. Quote Link to comment https://forums.phpfreaks.com/topic/75327-simple-problem/page/2/#findComment-381325 Share on other sites More sharing options...
sasa Posted October 30, 2007 Share Posted October 30, 2007 try <?php $names_in_form = 50; //change this number if (isset($_POST['submit'])) { $out = array(); for ($i = 1; $i <= $names_in_form; $i++){ $var_name = 'name_'.$i; if ($_POST[$var_name]) $out[] = $var_name.'='.$_POST[$var_name]; } $out = implode('&', $out); $h = fopen("names.txt",'w'); fwrite($h, $out); fclose($h); } if(file_exists("names.txt")){ $names = file_get_contents("names.txt"); $names1 = explode('&',$names); $names = array(); foreach ($names1 as $name){ $name = explode('=',$name); $names[$name[0]] = $name[1]; } } else $names = array(); echo '<form method="POST" action="">',"\n"; for ($i = 1; $i <= $names_in_form; $i++){ $var_name = 'name_'.$i; echo 'Name ', $i, ' <input type="text" name="',$var_name, '" value="',$x = array_key_exists($var_name,$names) ? $names[$var_name] : '' ,'"><br />',"\n"; } echo ' <input type="submit" name="submit" value="Submit"> </form>'; if (isset($_POST['submit'])) echo '<h2>In file write: ', $out,'</h2>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/75327-simple-problem/page/2/#findComment-381349 Share on other sites More sharing options...
pepperface Posted October 31, 2007 Author Share Posted October 31, 2007 Thanks! I've been off the board for about 12 hours catching up on two day's sleep! But in the interim another kind soul found a fix and emailed it to me. I'm in a meeting at the mo; so can't access it to post up but as soon as I'm back at my desk I'll sling up the fix. It does work!!! Thanks all... back soon... Quote Link to comment https://forums.phpfreaks.com/topic/75327-simple-problem/page/2/#findComment-381771 Share on other sites More sharing options...
pepperface Posted October 31, 2007 Author Share Posted October 31, 2007 <?php $File = "bookings.txt"; $Handle = fopen($File, 'a'); fwrite($Handle, "name1=".$name1."&name2=".$name2."&name3=".$name3."&name4=".$name4."&name5=".$name5); fclose($Handle); ?> Quote Link to comment https://forums.phpfreaks.com/topic/75327-simple-problem/page/2/#findComment-381786 Share on other sites More sharing options...
adam291086 Posted October 31, 2007 Share Posted October 31, 2007 oh so simple. HAHAHAHA Don't forget to click topic solved Quote Link to comment https://forums.phpfreaks.com/topic/75327-simple-problem/page/2/#findComment-381788 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.