meckr Posted June 21, 2006 Share Posted June 21, 2006 OK, I am trying to have one script prompt a user for a string (lets say a cd key) and have the user place it in a textbox as a variable. Then upon submitting the form, the script creates another php file with the user provided data placed inside the new php file.Here is my code for creating the new php file with the user data[code]if (file_exists ("data.php")) { @unlink ("inc/data.php"); } $read=@fopen ("blank_data.php", "r"); $result=@fread ($read, 1024); @fclose ($read); $result=str_replace ("{{userdata}}", $userdata, $result); $read=fopen ("data.php", "w"); fwrite ($read, $result); fclose ($read); chmod ("data.php", 0755);[/code]Now, my only real problem is, how do I create a textbox within a form and make whatever is placed inside the textbox a variable that can be posted to the new php file?I was thinking of something like (and it doesn't have to be inside a form necessarily)[code]<td width='25%' align='left' valign='top'>Enter data:</td><td width='75%' align='left' valign='middle'><textarea name='license' rows='3' cols='59'>".((isset($data))?"".$data."":"")."</textarea></td>[/code]If that makes any sense at all.Any help would be so much appreciated, I might just offer an award. [img src=\"style_emoticons/[#EMO_DIR#]/huh.gif\" style=\"vertical-align:middle\" emoid=\":huh:\" border=\"0\" alt=\"huh.gif\" /] Quote Link to comment https://forums.phpfreaks.com/topic/12549-posting-user-input-as-a-variable/ Share on other sites More sharing options...
wisewood Posted June 21, 2006 Share Posted June 21, 2006 Should get you started.<?phpif!($_POST){echo "<form method=post action=$PHP_SELF";echo "<input type=text name=cd_key>";echo "<input type=submit value=submit";echo "</form";}else{echo "The cd_key you input was: $_POST[cd_key]";}?> Quote Link to comment https://forums.phpfreaks.com/topic/12549-posting-user-input-as-a-variable/#findComment-48062 Share on other sites More sharing options...
meckr Posted June 21, 2006 Author Share Posted June 21, 2006 I would like to avoid a form if at all possible. i know this can be done as I know of other programs that use this type of code. I just can't figur out how it is done Quote Link to comment https://forums.phpfreaks.com/topic/12549-posting-user-input-as-a-variable/#findComment-48066 Share on other sites More sharing options...
wildteen88 Posted June 21, 2006 Share Posted June 21, 2006 What! You got to use a form in order to send the information to your script! How else is the information going to be sent to your script in order to be processed? Quote Link to comment https://forums.phpfreaks.com/topic/12549-posting-user-input-as-a-variable/#findComment-48070 Share on other sites More sharing options...
meckr Posted June 21, 2006 Author Share Posted June 21, 2006 sorry I missunderstood your post. I meant to say without a text box but within a text area and I guess it would still be the same only textarea instead of text. Quote Link to comment https://forums.phpfreaks.com/topic/12549-posting-user-input-as-a-variable/#findComment-48077 Share on other sites More sharing options...
wildteen88 Posted June 21, 2006 Share Posted June 21, 2006 Still need a form even if its a textarea. To autopupulate the textarea when the data is sent you can use this:[code]<td width='25%' align='left' valign='top'>Enter data:</td><td width='75%' align='left' valign='middle'><textarea name='license' rows='3' cols='59'><?php echo ((isset($data) ? $data : ''); ?></textarea></td>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/12549-posting-user-input-as-a-variable/#findComment-48081 Share on other sites More sharing options...
meckr Posted June 21, 2006 Author Share Posted June 21, 2006 Thanks for your help wildteen88 but It seems it won't work. I have tried it numerous times without success.So let me reiterate. I have a textarea that a user will use to place a license key into. Afterwhich the user, will hit the submit button. Then, a file called install_license.php and will be written to by placing the license key the user provided, into the a variable within intall_license.php. Then install_license.php will be renamed to license.php.How can this be accomplished. I have tried using my code above but i cannot get it to work. I have checked the permissions on install_license.php and they are set to 777.Now, a differnet method that would work just as well, is if I could somehow figure out how to insert the user provided license (from the textarea) into a db.Any help would be greatly appreciated. I just cannot figure it out for the life of me. I know this is simple stuff but I'm just racking my brain.Please assist? Quote Link to comment https://forums.phpfreaks.com/topic/12549-posting-user-input-as-a-variable/#findComment-48285 Share on other sites More sharing options...
wildteen88 Posted June 22, 2006 Share Posted June 22, 2006 Something like this:[code]<?php// check that the user has submitted the formif (isset($_POST['submit'])){ // open install_license.php $file = 'install_license.php'; $handle = fopen ($file, 'w'); $contents = "<?php\n\n\$key = \"" . $_POST['license'] . "\"\n\n?>"; // write contents to file: fwrite ($handle, $contents); // close the file fclose ($handle); // attempt to rename the file: if(!file_exists ('license.php')) { // rename install_license.php rename ($file, 'license.php'); } else { echo "Unabel to rename install_license.php as license.php already exists! Please delete license.php before continuing"; } echo "License added and file has been renamed!<br /><br />";}?><form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <b>License Key:</b><br /> <textarea name="license" cols="20" rows="5"><?php echo (isset($_POST['license']) ? $_POST['license'] : ''); ?></textarea><br /> <input type="submit" name="submit" value="Add license" /></form>[/code]Thats does what you want, create the file, set the variable and rename the file. Quote Link to comment https://forums.phpfreaks.com/topic/12549-posting-user-input-as-a-variable/#findComment-48419 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.