pass a value from a .php file to other .php file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ktiniatros
Forum Newbie
Posts: 1
Joined: Wed Feb 25, 2009 10:37 am

pass a value from a .php file to other .php file

Post by ktiniatros »

Hello,

i have the following php file:

Code: Select all

<html>
<head><title>win</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<body>
<?php
$bet=2.75;
?>
<form method="post" action="update.php">
        <input type="number" name="stake" size="5"/><br/>
        <input type="submit" value="place"/></form>
</body><html>
and i want to pass the value $bet*stake (number that user will type in the input number field of the form multiplied with my integer variable)
to the update.php file.
how do i do that?? im frustrated with the tutorials i googled.
thanks in advance.
asparak
Forum Newbie
Posts: 13
Joined: Tue Feb 24, 2009 3:38 pm

Re: pass a value from a .php file to other .php file

Post by asparak »

stab in the dark, but look at this example and see if it helps any.
http://www.tizag.com/phpT/examples/formex.php
granite
Forum Commoner
Posts: 44
Joined: Mon Feb 09, 2009 10:52 am

Re: pass a value from a .php file to other .php file

Post by granite »

You can use global variables, such as $_SESSION and $_POST.

Pass the value $bet to a global variable in the code you posted.
$_SESSION['bet'] = $bet;

Then, in your other php code, use
$stake = $_POST['stake'];
$bet = $_SESSION['bet'];
$fbet = $bet*$stake;
Post Reply