Jump to content

Just a slight problem sending all info from admin form to a public template??


harryuk

Recommended Posts

Hello follow PHP'ers

 

I have a form stored in my admin directory and a public temple named Products. I have a link on my header to access it!!!

 

I am using abit of Java script so when a product is selected (admin side) from a drop down menu named category it updates the sub-category drop down menu that is all working fine. What i cant work out is when a product is selected from the sub-category and the form is submited how to put all the stored data on to the public template products and how to what ever is selected from the sub-category echoes out under a header on the public template named what ever was selected.

 

Example


$product_glasses = "";
$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC");
$productCount = mysql_num_rows($sql);
if ($productCount > 0) {
while($row = mysql_fetch_array($sql)){ 
             $id = $row["id"];
		 $product_name = $row["product_name"];
		 $price = $row["price"];
		 $date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
		 $product_list .= "Product ID: $id - <strong>$product_name</strong> - $$price - $category - $subcategory       • <a href='inventory_list.php?deleteid=$id'>delete</a><br />";
    }
} else {
$product_glasses = "You have no products listed in your store yet";
}
?>
    <form action="inventory_list.php" enctype="multipart/form-data" name="myForm" id="myform" method="post">
    <table width="90%" border="0" cellspacing="0" cellpadding="6">
      <tr>
        <td width="20%" align="right">Product Name</td>
        <td width="80%"><label>
          <input name="product_name" type="text" id="product_name" size="64" />
        </label></td>
      </tr>
      <tr>
        <td align="right">Product Price</td>
        <td><label>
         £
          <input name="price" type="text" id="price" size="12" />
        </label></td>
      </tr>
      <tr>
        <td align="right">Category</td>
        <td><label>
          <select name="category" id="category">
          <option value="Clothing">Clothing</option>
          <option value="accessories">accessories</option>

          </select>
        </label></td>
      </tr>
      <tr>
        <td align="right">Subcategory</td>
        <td><select name="subcategory" id="subcategory">
        <option value=""></option>
          <option value="watches">watches</option>
          <option value="glasses">glasses</option>
          <option value="Shirts">Shirts</option>
          </select></td>
      </tr>
      <tr>
        <td align="right">Product Details</td>
        <td><label>
          <input type="submit" name="button" id="button" value="Add This Item Now" />
        </label></td>
      </tr>
    </table>
    </form>

 

Then have that echoed out in the public template products like so.

 


<body>

Glasses
<hr>
<? echo '$product_glasses' ?>
<br />
<br />
watches
<hr>
<? echo '$product_watches' ?> /////////How i would be able to echo this out ???? I know i have do perform some code under the sub-category section but i just dont know what??

PLEASE HELP

Thanks

Not sure I understand the question, but it sounds like a simple POST issue. when you POST variables through a form, you need to use $_POST + the elements html name to grab the value.

Here's an example:

two html elements called 'johnny' & 'Misty'

<select name="johnny"><option value="1">value is One</option></select>
<input type="text" name="Misty">

you grab them with:

echo $_POST['johnny'];
echo '<br>';
echo $_POST['Misty'];

 

in your case, I suggest you dump the entire $_POSt array to see what's in it first:

echo '<pre>';
print_r($_POST);
echo '</pre>';

 

hope this helps (and was what you were asking)

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.