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

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.