2 Replies - 549 Views - Last Post: 19 December 2011 - 11:50 PM Rate Topic: -----

#1 GunnySingh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 16-July 09

Code to output HTML form not working

Posted 19 December 2011 - 10:21 PM

Hey,

I'm just learning PHP and have run into this problem. My PHP code to print the user input data is not showing on a new page. It is working for one page and not for the other and am completely lost after spending a few hours on trying to figure out why. Would be great if someone can point out the flaw.

*PHP is running on the page, I tried it with a simple echo. However, the variables are not working.

production.php
	<form method="POST" action="prod2.php">
	Desired ending inventory of finished goods at end of Quarter 1: <input type="text" name="fingoodsqrt1" /> <br>
	Desired ending inventory of finished goods at end of Quarter 2: <input type="text" name="fingoodsqrt2" /> <br>
	Desired ending inventory of finished goods at end of Quarter 3: <input type="text" name="fingoodsqrt3" /> <br>
	Desired ending inventory of finished goods at end of Quarter 4: <input type="text" name="fingoodsqrt4" /> <br>
		
	<br>
	
	Total needs in quarter 1:<input type="text" name="needsqrt1" /> <br>
	Total needs in quarter 2:<input type="text" name="needsqrt2" /> <br>
	Total needs in quarter 3:<input type="text" name="needsqrt3" /> <br>
	Total needs in quarter 4:<input type="text" name="needsqrt4" /> <br>
	
	<br>
	
	Less beginning inventory of finished goods at end of Quarter 1: <input type="text" name="lessqrt1" /> <br>
	Less beginning inventory of finished goods at end of Quarter 2: <input type="text" name="lessqrt2" /> <br>
	Less beginning inventory of finished goods at end of Quarter 3: <input type="text" name="lessqrt3" /> <br>
	Less beginning inventory of finished goods at end of Quarter 4: <input type="text" name="lessqrt4" /> <br>
	</form>
	
	<form name="input" action="prod2.php">
<input type="submit" value="Next page" />
</form>



prod2.php
<html>
<body>

You have entered the following data, to confirm please click "Next".

<?php
	$x=$_POST['fingoodsqrt1'];
	$y=$_POST['fingoodsqrt2'];
	$z=$_POST['fingoodsqrt3'];
	$a=$_POST['fingoodsqrt4'];
	$b=$_POST['needsqrt1'];
	$c=$_POST['needsqrt2'];
	$d=$_POST['needsqrt3'];
	$e=$_POST['needsqrt4'];
	$f=$_POST['lessqrt1'];
	$g=$_POST['lessqrt2'];
	$h=$_POST['lessqrt3'];
	$i=$_POST['lessqrt4'];	?>
	
	<?php echo "$x" ?>
	
	<?php echo "hello" ?>
	<?php
// Make a MySQL Connection
mysql_connect(localhost, "root", "haha") or die(mysql_error());
mysql_select_db("project") or die(mysql_error());


// Insert a row of information into the table "production"
mysql_query("INSERT INTO production VALUES('', '$x', '$y', '$z', '$a', '$b', '$c', '$d', '$e', '$f', '$g','$h', '$i') ") 
or die(mysql_error());  


mysql_close();

?>
<br>
<br>

Fin goods Qrt 1: <?php echo $_POST["fingoodsqrt1"]; ?><br />
Fin goods Qrt 2: <?php echo $_POST["fingoodsqrt2"]; ?> <br>
Fin goods Qrt 3: <?php echo $_POST["fingoodsqrt3"]; ?>  <br>
Fin goods Qrt 4: <?php echo $_POST["fingoodsqrt4"]; ?>  <br>
<br>
Needs Qrt 1: <?php echo $_POST["needsqrt1"] ?>  <br>
Needs Qrt 2: <?php echo $_POST["needsqrt2"]; ?> <br>
Needs Qrt 3: <?php echo $_POST["needsqrt3"]; ?> <br>
Needs Qrt 4: <?php echo $_POST["needsqrt4"]; ?> <br>
<br>
Less Qrt 4: <?php echo $_POST["lessrawqrt4"]; ?> <br>
Cost / unit raw: <?php echo $_POST["costraw"]; ?> <br>

<a href="manufacturing.html"> NEXT </a>

</body>
</html>



Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Code to output HTML form not working

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4421
  • View blog
  • Posts: 12,289
  • Joined: 18-April 07

Re: Code to output HTML form not working

Posted 19 December 2011 - 11:42 PM

You are missing semicolons...


<?php echo "$x"; ?>

<?php echo "hello"; ?>


Needs Qrt 1: <?php echo $_POST["needsqrt1"]; ?>  <br>



These three lines above, notice how I have put in semicolons. Now after fixing these, you want your submit button to be inside the same form tags as your fields.

Your first form doesn't have a submit button. You put that submit button in a completely separate form... a form with no fields. So take the form submit button out of that second form and move it up to the first form.

Then it should work fine. :)
Was This Post Helpful? 0
  • +
  • -

#3 GunnySingh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 16-July 09

Re: Code to output HTML form not working

Posted 19 December 2011 - 11:50 PM

1. I feel dumb.
2. Martyr, you are my god. Thanks.

Solved, btw. Thanks a lot martyr! :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1