Jump to content

Displaying POST variables from a Form


tkessel

Recommended Posts

Hi everyone! I really need some help on this.

 

I have a form that pulls product data from a MySQL db to use. I also have two input fields for the user to enter "percent price markup" or "manual price markup" that I will need to calculate the new price.

 

Here is the form, but I don't know how to output all of the variables in a table:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script>
<script type="text/javascript" src="js/lightbox.js"></script>
<link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" />


</head>


<body>
<form action="output.php" method="post">
<table border="1">
  <tr>
    <td>Image</td>
    <td>Name</td>
    <td>Cost</td>
    <td>Markup<br />(%)</td>
    <td>Manual</td>
  </tr>
<?php
require("constants.php");


$query="SELECT * FROM products";
$result=mysql_query($query);


$num=mysql_numrows($result);


mysql_close();


echo "<b><center>Database Output</center></b><br><br>";


$i=0;
while ($i < $num) {


$id=mysql_result($result,$i,"id");
$product=mysql_result($result,$i,"product");
$description=mysql_result($result,$i,"description");
$pcategory=mysql_result($result,$i,"pcategory");
$image_big=mysql_result($result,$i,"image_big");
$image_thumb=mysql_result($result,$i,"image_thumb");
$price=mysql_result($result,$i,"price");
$price=number_format($price, 2, '.', '');
echo "<tr>
    <td><a href=\"images/$image_big\" rel=\"lightbox\"><img src=\"thumbs/$image_thumb\" width=\"129\" height=\"83\" /></a></td>
    <td><strong>$product</strong><br />$description</td>
    <td><input type=\"hidden\" name=\"price $id\" value=\"$price\" />\$$price</td>
    <td><input type=\"text\" name=\"markup$id\" /></td>
<td><input type=\"text\" name=\"manual$id\" /></td>
  </tr>";


$i++;
}


?>
</table>
<input type="submit" />
</form>
</body>
</html>

 

I am new to PHP and am learning as fast as possible, but I need to complete this project as soon as possible.

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/205913-displaying-post-variables-from-a-form/
Share on other sites

try something like this

<table>
<?php
require("constants.php");
$query="SELECT * FROM products";
$result=mysql_query($query);
while($row=mysql_fetch_array($result)){
$id= $row["id"];
$description = $row["description"];
echo '<tr><td>'.$id.'</td><td>'.$description.'</td></tr>';
}
mysql_close();
?>
</table>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.