gavin1512 Posted January 9, 2008 Share Posted January 9, 2008 Good afternoon all, I am havign another small problem that is becoming quite frustrating...Basically when selecting a product from a list of search results for the user to add to the basket, I have a text box called "quantity" which the user enters the Quantity then clicks the add button which links to the adduser script. At the moment it is taking all the DB values fine but not the quantity, at the bottom of page when I hover over the button it shows all the values e.g. &productnumber = 00E140dn &price = 342.10 but after $quantity = it is just blank. Here is the code I am using on the href button: <div align="center"><a href="addtoorder.php?productnumber=<?php echo $row['productnumber']?> &type=<?php echo $row['type']?> &description=<?php echo $row['description']?> &price=<?php echo $row['price']?> &quantity=<?php $_GET['quantity']?> " > [+] </a></div> Quote Link to comment https://forums.phpfreaks.com/topic/85194-difficulty-taking-value-from-text-box-to-array/ Share on other sites More sharing options...
drummer101 Posted January 9, 2008 Share Posted January 9, 2008 Since you're using $_GET is the quantity already in the URL? Quote Link to comment https://forums.phpfreaks.com/topic/85194-difficulty-taking-value-from-text-box-to-array/#findComment-434632 Share on other sites More sharing options...
nikefido Posted January 9, 2008 Share Posted January 9, 2008 can you show us your HTML form code? Quote Link to comment https://forums.phpfreaks.com/topic/85194-difficulty-taking-value-from-text-box-to-array/#findComment-434643 Share on other sites More sharing options...
gavin1512 Posted January 9, 2008 Author Share Posted January 9, 2008 here is the code for the whole form (sorry is a bit untidy I am using dreamweaver) <?php session_start(); if (isset($_SESSION['username']) == false){ header("Location:home.php"); exit(); } require "connect.php"; if (($_GET['text'] == "") || ($_GET['field'] == "*")) { $query = "SELECT * FROM product ORDER BY productnumber limit 0, 10"; } else { $query = "SELECT * FROM product WHERE ".$_GET['field']. " like '%".$_GET['text']."%' ORDER BY productnumber"; } $result = @mysql_query($query, $connection) or die ("Unable to perform query<br />$query"); ?> <!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=iso-8859-1" /> <!-- TemplateBeginEditable name="doctitle" --> <title>Untitled Document</title> <!-- TemplateEndEditable --> <!-- TemplateBeginEditable name="head" --><!-- TemplateEndEditable --> <style type="text/css"> <!-- #Layer1 { position:absolute; width:988px; height:680px; z-index:1; left: 215px; top: 104px; } #Layer2 { position:absolute; width:389px; height:435px; z-index:2; left: 17px; top: 107px; } #Layer3 { position:absolute; width:200px; height:51px; z-index:3; left: 6px; top: -86px; } #Layer4 { position:absolute; width:267px; height:39px; z-index:3; left: 713px; top: -73px; } .style1 {font-family: Arial, Helvetica, sans-serif} --> </style> </head> <body> <p class="style1"><img src="back.jpg" width="1199" height="652" align="top" /></p> <?php switch ($_SESSION['access']) { case 'User': include('user side.php'); break; case 'Manager': include('manager side.php'); break; case 'Fulfilment': include('fulfil side.php'); break; case 'Admin': include('admin side.php'); break; } ?> <div class="style1" id="Layer1"> <table width="979" border="0"> <form method="get" action="productsearch.php" name="productsearch"> <tr> <td width="136"> </td> <td width="157"> </td> <td width="172"> </td> <td width="175"> </td> <td width="152"> </td> </tr> <tr> <td><div id="Layer3"> <table width="200" border="0"> <tr> <td height="38">Product Search Page </td> </tr> </table> </div></td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td colspan="2"><p>Please enter search criteria </p></td> <td><input name="text" type="text" id="text" /></td> <td><p><select name="field" id="field"> <option value="*">Choose category</option> <option value="productnumber">Product Number</option> <option value="type">Product Type</option> <option value="description">Description</option> <option value="price">Price</option> </select></p></td> <td><input name="search" type="submit" id="search" value="Search" /></td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td><div align="right">Page</div></td> <td><a href="productsearch.php">1 </a><a href="productsearch2.php">2 </a><a href="productsearch3.php">3 </a><a href="productsearch4.php">4</a></td> </tr> </form> <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td><strong>Product Number </strong></td> <td><strong>Product Type </strong></td> <td><strong>Description</strong></td> <td><strong>Price</strong></td> <td><strong>Quantity</strong></td> <td width="161"><div align="center"><strong>Add to Order</strong></div></td> </tr> <?php while($row= mysql_fetch_array($result)) { ?> <tr> <form action="addtoorder.php" method="get"> <td><?php echo $row['productnumber']?></td> <td><?php echo $row['type']?></td> <td><?php echo $row['description']?></td> <td><?php echo $row['price']?></td> <td><input name="quantity" type="text"></td> <td><div align="center"><a href="addtoorder.php?productnumber=<?php echo $row['productnumber']?> &type=<?php echo $row['type']?> &description=<?php echo $row['description']?> &price=<?php echo $row['price']?> &quantity=<?php $_GET['quantity']?> " > [+] </a></div></td> </form> </tr> <?php } ?> </table> </div> <p class="style1"> </p> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/85194-difficulty-taking-value-from-text-box-to-array/#findComment-434652 Share on other sites More sharing options...
gavin1512 Posted January 9, 2008 Author Share Posted January 9, 2008 I guessing the problem is with the &quantity=<?php $_GET['quantity'], i just put that in to try. Quote Link to comment https://forums.phpfreaks.com/topic/85194-difficulty-taking-value-from-text-box-to-array/#findComment-434656 Share on other sites More sharing options...
duclet Posted January 9, 2008 Share Posted January 9, 2008 You might want to change <?php $_GET['quantity']; ?> to <?php echo $_GET['quantity']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/85194-difficulty-taking-value-from-text-box-to-array/#findComment-434669 Share on other sites More sharing options...
nikefido Posted January 9, 2008 Share Posted January 9, 2008 i think you are kinda putting the cart in front of the horse here - you are telling php to retrieve $_GET variables before they have even been set (if i'm reading this correctly - please correct me if I am wrong). What I think you should do is to make the form action POST and use a submit button! <form action="addtoorder.php method="post"> use this at the end instead of your anchor tag (link) <input type="submit" name="submit" value="Add to Cart"> Quote Link to comment https://forums.phpfreaks.com/topic/85194-difficulty-taking-value-from-text-box-to-array/#findComment-434675 Share on other sites More sharing options...
gavin1512 Posted January 9, 2008 Author Share Posted January 9, 2008 I just tried to $_GET as a coudln't think of any other possibility, as being inexperienced with PHP. I have the GET methods in the addtoorder.php shown below. I can either get the values from text boxes or from the database, but have not got from both in the same form. Hope this makes my problem clearer. Is this solved using the POST method? <?php session_start(); if (isset($_SESSION['username']) == false){ header("Location:home.php"); exit(); } // product array to store product details $product = array(); $product['productnumber']= $_GET['productnumber']; $product['type']= $_GET['type']; $product['description']= $_GET['description']; $product['price']= $_GET['price']; $product['quantity'] = $_GET['quantity']; $found = false; if(isset($_SESSION['order'])){ foreach($_SESSION['order'] as $key => $anotherproduct) { if ($_SESSION['order'] [$key] ['productnumber'] == $_GET['productnumber']) { $found = true; } } } //add the print to the cart if not there already if ($found ==false) { $_SESSION['order'] [] = $product; } header("Location:productsearch.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/85194-difficulty-taking-value-from-text-box-to-array/#findComment-434685 Share on other sites More sharing options...
revraz Posted January 9, 2008 Share Posted January 9, 2008 I would suggest that you look up on how $_GET functions. That will probably help you understand it better. I just tried to $_GET as a coudln't think of any other possibility, as being inexperienced with PHP. I have the GET methods in the addtoorder.php shown below. I can either get the values from text boxes or from the database, but have not got from both in the same form. Hope this makes my problem clearer. Is this solved using the POST method? Quote Link to comment https://forums.phpfreaks.com/topic/85194-difficulty-taking-value-from-text-box-to-array/#findComment-434689 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.