Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to pass value of $x (embedded) in html form section to php section 1

Status
Not open for further replies.

amir4oracle

Programmer
Nov 3, 2004
46
0
0
CA
How can we pass value of $x php variable embedded in html form section to php section (or form process section)?

The simple version of the code (register.php) is as follows :

Code:
<?php  
//[b]php section[/b]
if (isset ($_POST['submit'])) 
{
  $emal_addr = $_POST['emal_addr'];
  echo "$emal_addr";

[b]  echo "$x";[/b]
.
.

}
?>

[b]html form section[/b]
<form action="register.php" method="post">
  <input type="text" name="emal_addr" value="<?php echo $_POST['emal_addr']; ?>"/>
  <?php
[b]    $x = 7;[/b]
  ?>
.
.
  <input type="submit" value="Submit" name="submit">
</form>

In this case the value of emal_addr passes and echoes fine but how can we pass and echo the value of a php variable $x in this case to the php section.

Your help is highly appreciated as always thanks in advance.
Best regards,
Amir Khan
 
Uh, move the statement

$x = 7;

to a line before

echo $x;

?

I don't really understand what you're asking here. A PHP script is processed from top to bottom. There is no mechanism to automagically make something that happens later in a script happen earlier.



Want the best answers? Ask the best questions! TANSTAAFL!
 
I think what the OP means is to get the value of $x passed along with the form values when the form is submitted.

You could set it in a hidden field, and it would get passed.

Code:
<?
$x=7;
?>
<input type=hidden name="x" value="<? echo $x; ?>">

Or you could have it in a session variable, then it would always be available.
$_SESSION['x']=7;








----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Actually $x contains randomly generated numbers which is displayed in the form, so I cant generate it in the php section.

According to you in this situation if we generate it earlier in the php section then the value of $x changes in the form after submit is pressed.

The random numbers are used for authentic form fill up, as captcha, the we have to fill random nos. while filling out yahoo sign for eg. so that its made sure that its filled up by a human not thru a program.
 
$_SESSIONS, or a hidden field work perfectly for what you want.







----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
In fact I already tried with the hidden field but it was not working now I tried with $_SESSIONS, both ways its not working.

Vacunita can you kindly give a sample coding, maybe maybe I am doing something wrong. Although I have been working on C and Oracle since more than ten years, so I am pretty sure syntactically I won't be wrong. PHP fascinates me very much being such a nice web tecnology, relatively I am new at it, this is a business project I am working on.
 
Me said:
Code:
<?
$x=7;
?>
<input type=hidden name="x" value="<? echo $x; ?>">

And then you use it like:
Code:
if (isset ($_POST['submit']))
{
  $emal_addr = $_POST['emal_addr'];
  echo "$emal_addr";

  echo "[red]$_POST['x'][/red]";

or even
[blue]
$x=$_POST['x'];
echo $x;
[/blue]

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top