thminco Posted April 28, 2011 Share Posted April 28, 2011 I have a php string variable that is created by php code within an html form ($answer). I need to pass this string variable along with all the html form input data to another php script specified with the form "action" (post method). All the html form input data is coming thru fine but not the variable ($answer). How do I do this? Here is the php code for importing html form data at the script called in the form action: $languages = $_POST['languages']; $answergiven = $_POST['answergiven']; $problemanswer = $_POST['$answer']; 'languages' and 'answergiven' are form inputs and come thru fine. '$answer' does not get passed to the second script. How do I do this? Here is the php code within the first html form <?php // OPEN DATABASE $username="servics3_sample"; $password="sample"; $database="servics3_sample"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); // GENERATE RANDOM PROBLEM NUMBER $probnum = (rand ( 1 , 9 )); echo $probnum; // RETRIEVE ANTI-SPAM PROBLEM $query="SELECT * FROM liasantispam WHERE `problem number` LIKE '%$probnum%' "; $result=mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query); $firstnum=mysql_result($result,0,"first number"); $operator=mysql_result($result,0,"operator"); $secondnum=mysql_result($result,0,"second number"); $answer=mysql_result($result,0,"answer"); echo $firstnum," ",$operator," ",$secondnum," = "; mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/234932-passing-string-variable-from-html-form-to-another-php-script/ Share on other sites More sharing options...
Muddy_Funster Posted April 28, 2011 Share Posted April 28, 2011 You can't POST a variable - only a form element. if you want to POST $answer add it to the form as a hidden field <input type="hidden" name="answer" value="<?php echo $answer ?>" /> This will POST the value of $answer into the array variable $_POST['answer'] and is the easiest solution to your question. Quote Link to comment https://forums.phpfreaks.com/topic/234932-passing-string-variable-from-html-form-to-another-php-script/#findComment-1207433 Share on other sites More sharing options...
thminco Posted April 28, 2011 Author Share Posted April 28, 2011 Thank you muddy funster!....That works great!! Really appreciate your help as I am a total newbie to php!! Tom Quote Link to comment https://forums.phpfreaks.com/topic/234932-passing-string-variable-from-html-form-to-another-php-script/#findComment-1207556 Share on other sites More sharing options...
Muddy_Funster Posted April 28, 2011 Share Posted April 28, 2011 No worries, let us know if you have any other issues. Quote Link to comment https://forums.phpfreaks.com/topic/234932-passing-string-variable-from-html-form-to-another-php-script/#findComment-1207566 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.