Jump to content

Recommended Posts

hi guys

 

i have two pages they are both .php,

step1.php has form on it that will pass the value on step2.php

 

but it give me an error below,

Notice: Undefined variable: squareyard in /home/travels/public_html/walkie/step2.php on line 19

 

here is step1.php

<?php
session_start();
?>

<br><br>
<center>
<h1>Step 1. Results</h1>
<br>
<div align='center'>
  <table width='60%'  border='0'>
    <tr>
      <td bgcolor='#99FFFF'><strong>Converting Sand to gallons: </strong></td>
    </tr>
  </table>
</div>	


<?php
//"First Name:  " . $_POST['fname'] .    			

//initialize variables
$coaltar = 100;
$water = $_POST['water'];
$sand = $_POST['sand'];
$additive = $_POST['additive'];

echo "<br>";
echo "<center>";
echo "<strong>";
echo "sand x 100 (CT) = x divided by 20 = x gallons of sand";
echo "</strong>";
echo "</center>";

$sandtogallon = $sand * 100 / 20;

//100 + 30 + 15 (sand in gallons) + 2 (gal of additive) = 147 
$maingallonformula = 100+$water+$sandtogallon+$additive;
$totalgallonsmaterial = 100/$maingallonformula;

echo "<br>";
?>
<div align='center'>
  <table width='60%'  border='0'>
    <tr>
	<td bgcolor='#FFFFCC'>
<?php
		echo "<strong>";
		echo $sandtogallon . " gallons of sand";
		echo "<br>";
		echo "<br>";			
		echo "Total gallons of materials: " . $totalgallonsmaterial;
		echo "</strong>";

//storing it into session
$_SESSION['totalgallonsmaterial2'] = $totalgallonsmaterial;

?>
	    </tr>
	</td>
  </table>
</div>	

<br>
<div align='center'>
  <table width='60%'  border='0'>
    <tr>
      <td bgcolor='#99FFFF'><strong>Total gallons needed: </strong></td>
    </tr>
  </table>
</div>	

<?php
echo "<br>";
echo "<center>";
echo "<strong>";
echo "Sq. Yards (divided by) 5 = Total gallons needed";
echo "</strong>";
echo "</center>";



?>

<div align="center">
  <form name="form1" method="post" action="step2.php">
    <table width="20%"  border="1">
      <tr>
        <td width="81%"><div align="center"><strong> Sq. Yards </strong></div></td>
        <td width="19%"><div align="center"></div></td>
      </tr>
      <tr>
        <td><div align="center">
          <input type="text" name="squareyard">
        </div></td>
        <td><div align="center"><strong>/ 5</strong></div></td>
      </tr>
    </table>
    <p>
      <input type="submit" name="Submit" value="calculate">
    </p>
  </form>
</div>

 

here is step2.php

<?php
session_start();
//$_SESSION['totalgallonsmaterial2'] = $totalgallonsmaterial;
//echo $_SESSION['totalgallonsmaterial2'];
?>

<br><br>
<center>
<h1>Step 2. Results</h1>
<br>
<?php


echo $_SESSION['totalgallonsmaterial2'];

//Sq. Yards (divided by) 5 = Total gallons needed
$gallonsofmaterial2 = $squareyard * 5;

echo "<strong>";
echo $gallonsofmaterial2 . " gallons of material needed";
echo "</strong>";

?>

 

 

I'm wondering if the session_start() affected this?

any nice guess?

 

thanks in advance.  :D

 

 

Link to comment
https://forums.phpfreaks.com/topic/66474-underfined-variable-session/
Share on other sites

Try the pages below

 

step1:

<?php
session_start();
//$_SESSION['totalgallonsmaterial2'] = $totalgallonsmaterial;
//echo $_SESSION['totalgallonsmaterial2'];
?>

<br><br>
<center>
<h1>Step 2. Results</h1>
<br>
<?php


echo $_SESSION['totalgallonsmaterialtwo'];

//Sq. Yards (divided by) 5 = Total gallons needed
$gallonsofmaterial2 = ($squareyard * 5);

echo "<strong>";
echo $gallonsofmaterial2 . " gallons of material needed";
echo "</strong>";

?>

 

step2.php

<?php
session_start();
?>

<br><br>
<center>
<h1>Step 1. Results</h1>
<br>
<div align='center'>
  <table width='60%'  border='0'>
    <tr>
      <td bgcolor='#99FFFF'><strong>Converting Sand to gallons: </strong></td>
    </tr>
  </table>
</div>	


<?php
//"First Name:  " . $_POST['fname'] .    			

//initialize variables
$coaltar = 100;
$water = $_POST['water'];
$sand = $_POST['sand'];
$additive = $_POST['additive'];

echo "<br>";
echo "<center>";
echo "<strong>";
echo "sand x 100 (CT) = x divided by 20 = x gallons of sand";
echo "</strong>";
echo "</center>";

$sandtogallon = ($sand * 100 / 20);

//100 + 30 + 15 (sand in gallons) + 2 (gal of additive) = 147 
$maingallonformula = (100+$water+$sandtogallon+$additive);
$totalgallonsmaterial = (100/$maingallonformula);

echo "<br>";
?>
<div align='center'>
  <table width='60%'  border='0'>
    <tr>
	<td bgcolor='#FFFFCC'>
<?php
		echo "<strong>";
		echo $sandtogallon . " gallons of sand";
		echo "<br>";
		echo "<br>";			
		echo "Total gallons of materials: " . $totalgallonsmaterial;
		echo "</strong>";

//storing it into session
$_SESSION['totalgallonsmaterialtwo'] = $totalgallonsmaterial;

?>
	    </tr>
	</td>
  </table>
</div>	

<br>
<div align='center'>
  <table width='60%'  border='0'>
    <tr>
      <td bgcolor='#99FFFF'><strong>Total gallons needed: </strong></td>
    </tr>
  </table>
</div>	

<?php
echo "<br>";
echo "<center>";
echo "<strong>";
echo "Sq. Yards (divided by) 5 = Total gallons needed";
echo "</strong>";
echo "</center>";



?>

<div align="center">
  <form name="form1" method="post" action="step2.php">
    <table width="20%"  border="1">
      <tr>
        <td width="81%"><div align="center"><strong> Sq. Yards </strong></div></td>
        <td width="19%"><div align="center"></div></td>
      </tr>
      <tr>
        <td><div align="center">
          <input type="text" name="squareyard">
        </div></td>
        <td><div align="center"><strong>/ 5</strong></div></td>
      </tr>
    </table>
    <p>
      <input type="submit" name="Submit" value="calculate">
    </p>
  </form>
</div>

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.