Jump to content

Passing string variable from html form to another php script


thminco

Recommended Posts

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();

 

?>

 

Link to comment
Share on other sites

:code_php_tags::anim_rules::code_php_tags:

 

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.

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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