Jump to content

Recommended Posts

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!!! :o

 

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 ;D

 

Thanks!!!

Link to comment
https://forums.phpfreaks.com/topic/75327-simple-problem/page/2/#findComment-381298
Share on other sites

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.

 

Link to comment
https://forums.phpfreaks.com/topic/75327-simple-problem/page/2/#findComment-381325
Share on other sites

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>';
?>

Link to comment
https://forums.phpfreaks.com/topic/75327-simple-problem/page/2/#findComment-381349
Share on other sites

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!!!  ;D

 

Thanks all... back soon...

Link to comment
https://forums.phpfreaks.com/topic/75327-simple-problem/page/2/#findComment-381771
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.