Jump to content

avincent

Members
  • Posts

    34
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

avincent's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. My apologize. This is the situation. I have a page which is the code I provided. The page has a form. The form has a table row with four input fields. The first field on the page is a drop down box that is populated with data from the database. Once a user selects an option in the first drop down box it will populate the second drop down box with information that corresponds to the selection of the first drop down box. If I leave only these four fields I can get the functionality of the drop down population to work just fine, but what I want to do is have a second table row with a set of fields that are identical to the previous row and for it to have the same functionality of selecting the first drop drop down in that row to populate the second drop down in that row. The issue that I am having is that currently the first drop-down box in the first row populates the data in the second drop-down in the first row via a javascript function that refreshes the page in order for the second drop down to know what is selected. When I select an option in the first drop-down box of the second row or possibly a third row nothing happens. The second drop down box of the second row should populate data with what corresponds to the selection of the first drop-down of the second row. Essentially I want the user to be able to do what they are doing in the first row over and over again. I hope this makes more sense.
  2. Wow. I didnt realize this was as hard of an issue as it is. If there is anyone that might be able to at least point me in the right direction that would be great.
  3. I want to be able to submit values from mutiple dropdown boxes that are generated by info from my mysql database. I have been able to get it to work with one set of dropdowns, but I want my second set of dropdowns to be able to have the same functionality as the first set of dropdowns without messing up the data from the first set. Then after the user have selected all of the fileds they want I send that data to a different page to display. I know this may seem confusing, but it is just hard for me to explain. Please help and if more questions are needed I will be happy to communicate to get this problem worked out. Here is my code: <?php session_start(); include("db_connect.php"); ?> <!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <title></title> <SCRIPT language=JavaScript> function reload(form) { var val=form.cat.options[form.cat.options.selectedIndex].value; self.location='shelf-talker.php?cat=' + val ; } </script> </head> <body> <ul> <li><a href="search.php" target="_self">Update/Delete</a></li> <li><a href="add-products.php" target="_self">Add Products</a></li> <li><a href="add-categories.php" target="_self">Add Categories</a></li> <li><a href="shelf-talker.php" target="_self">Shelf Talker</a></li> <li><a href="book-page.php" target="_self">Book Page</a></li> </ul> <h1>Shelf Talker</h1> <p>Search Products</p> <?php echo "<form method=post name=f1 action='shelf-talker-results.php'>"; ?> <?php @$cat=$_GET['cat']; // If register_global is off use this if(strlen($cat) > 0 and !is_numeric($cat)){ // Check if $cat is numeric or not. echo "Data Error"; exit; } // First list box// $quer2=mysql_query("SELECT product_categories_name, product_categories_id FROM tbl_product_categories"); // End of First list box //Check if category is selected else we display all the subcategories if(isset($cat) and strlen($cat) > 0){ $quer=mysql_query("SELECT product_name, product_id, join_category_id, join_product_id FROM tbl_product, tbl_join_products_categories WHERE join_category_id=$cat AND product_id=join_product_id order by product_name"); } //end of query for second subcategory drop down list box //Starting of first drop downlist echo "First Item<br>Category: <select name='cat' onchange=\"reload(form)\"><option value=''>Select one</option>"; while($noticia2 = mysql_fetch_array($quer2)) { if($noticia2['product_categories_id']==@$cat){echo "<option selected value='$noticia2[product_categories_id]'>$noticia2[product_categories_name]</option>"."<BR>";} else{echo "<option value='$noticia2[product_categories_id]'>$noticia2[product_categories_name]</option>";} } echo "</select>"; //End the first drop down list //Starting of second drop downlist echo " Product: <select name='subcat'><option value=''>Select one</option>"; while($noticia = mysql_fetch_array($quer)) { echo "<option value='".urlencode($noticia["product_name"])."'>".$noticia["product_name"]."</option>"; } echo "</select>"; //End the second drop down list echo " Bin #: <input type='text' name='bin' value=''> Price: <input type='text' name='price'> <br><br>"; //Additional fields ?> <?php @$second_cat=$_GET['second_cat']; // If register_global is off use this if(strlen($second_cat) > 0 and !is_numeric($second_cat)){ // Check if $cat is numeric or not. echo "Data Error"; exit; } // First list box// $second_quer2=mysql_query("SELECT product_categories_name, product_categories_id FROM tbl_product_categories"); // End of First list box //Check if category is selected else we display all the subcategories if(isset($second_cat) and strlen($second_cat) > 0){ $second_quer=mysql_query("SELECT product_name, product_id, join_category_id, join_product_id FROM tbl_product, tbl_join_products_categories WHERE join_category_id=$second_cat AND product_id=join_product_id order by product_name"); } //end of query for second subcategory drop down list box //Starting of first drop downlist echo "First Item<br>Category: <select name='second_cat' onchange=\"reload(form)\"><option value=''>Select one</option>"; while($second_noticia2 = mysql_fetch_array($second_quer2)) { if($second_noticia2['product_categories_id']==@$second_cat){echo "<option selected value='$second_noticia2[product_categories_id]'>$second_noticia2[product_categories_name]</option>"."<BR>";} else{echo "<option value='$second_noticia2[product_categories_id]'>$second_noticia2[product_categories_name]</option>";} } echo "</select>"; //End the first drop down list //Starting of second drop downlist echo " Product: <select name='second_subcat'><option value=''>Select one</option>"; while($second_noticia = mysql_fetch_array($second_quer)) { echo "<option value='".urlencode($second_noticia["product_name"])."'>".$second_noticia["product_name"]."</option>"; } echo "</select>"; //End the second drop down list echo " Bin #: <input type='text' name='second_bin' value=''> Price: <input type='text' name='second_price'> <br><br>"; //Additional fields ?> <?php echo "<input type=submit value=Submit name=submit>"; echo "</form>"; ?> </body> </html>
  4. I figured it out on my own. Seems that if i give each form a hidden field and unique form name and use the function array_key_exists() it knows which form to process.
  5. I have a PHP page that could display multiple forms depending on how many records correspond to the select made on the previous page. If the results page displays more than one form the user is only able to update the last form regardless if they make changes to the first form and use the update button for that form. I am trying to be able to tell my MySQL database to update records from the form that has the update button the user clicks and only update the data that corresponds to that form and no others. Below find the code being used: <?php session_start(); include("db_connect.php"); ?> <!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <title></title> <!-- OF COURSE YOU NEED TO ADAPT NEXT LINE TO YOUR tiny_mce.js PATH --> <script type="text/javascript" src="jscripts/tiny_mce/tiny_mce.js"></script> <script type="text/javascript"> tinyMCE.init({ // General options mode : "textareas", theme : "advanced" }); </script> </head> <body> <h1>Search Results</h1> <br> <hr> <?php if(isset($_POST['submit'])){ $subcat = urldecode($_POST['subcat']); $subcat = mysql_real_escape_string($subcat); if(isset($subcat) and strlen($subcat) > 0){ $sql = "SELECT * FROM `tbl_product` WHERE `product_name` ='{$subcat}'"; $query = mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_array($query)) { $product_id= $row['product_id']; $product_sku= $row["product_sku"]; $product_name= urlencode($row["product_name"]); $product_short_description= $row["product_short_description"]; $product_long_description= $row["product_long_description"]; $product_active= $row["product_active"]; echo "<form method='post' action='search-results.php'><table width='700' align='center'><tr><td><h3>" . urldecode($product_name) . "</h3></td></tr>"; echo "<tr><td><label for='product_id'>Product Active: <br><input type='checkbox' name='" . "active" . $product_id . "' value='" . $product_active . "'></td>"; echo "<td><label for='product_id'>Product ID: <br><input type='textbox' name='product_id' value='" . $product_id . "'></td>"; echo "<td><label for='product_id'>Product SKU: <br><input type='textbox' name='product_sku' value='" . $product_sku . "'></td>"; echo "<td><label for='product_id'>Product Name: <br><input type='textbox' name='subcat' value=\"" . urldecode($product_name) . "\"></td></tr>"; echo "<tr><td colspan='4'><textarea cols='60' rows='1' name='product_short_description'>" . $product_short_description . "</textarea></td></tr>"; echo "<tr><td colspan='4'><textarea cols='60' rows='4' name='product_long_description'>" . $product_long_description . "</textarea></td></tr>"; echo "<tr><td><input type='submit' name='delete' value='Delete'></td><td> </td><td><input type='submit' name='update' value='Update'></td></tr>"; echo "<tr><td colspan='4'><br><br><hr></td></tr></table></form>"; } } } ?> <?php if(isset($_POST['update'])){ $subcat = urldecode($_POST['subcat']); $subcat = mysql_real_escape_string($subcat); $product_id = $_POST['product_id']; $product_sku = $_POST['product_sku']; $product_short_description = $_POST['product_short_description']; $product_long_description = $_POST['product_long_description']; $sql = "UPDATE tbl_product SET product_name = '" . $subcat . "' , product_id = '" . $product_id . "' , product_sku = '" . $product_sku . "' , product_short_description = '" . $product_short_description . "' , product_long_description = '" . $product_long_description . "' WHERE product_id = '" . $product_id . "';"; //$sql = "SELECT * FROM `tbl_product` WHERE `product_name` ='{$subcat}'"; $query = mysql_query($sql) or die(mysql_error()); } ?> <?php if(isset($_POST['delete'])){ $subcat = urldecode($_POST['subcat']); $subcat = mysql_real_escape_string($subcat); $product_id = $_POST['product_id']; $product_sku = $_POST['product_sku']; $product_short_description = $_POST['product_short_description']; $product_long_description = $_POST['product_long_description']; $sql = "DELETE FROM tbl_product WHERE product_id = '" . $product_id . "';"; //$sql = "SELECT * FROM `tbl_product` WHERE `product_name` ='{$subcat}'"; $query = mysql_query($sql) or die(mysql_error()); } ?> </body> </html>
  6. I think I got it. I did your suggestion for urlencode on the sending page and then a urldecode on the receiving page and it is working great. TYVM
  7. When I run the code as is the option value is: <option value='Ca' Montini'> When I change the code to what you suggested I get this as what displays on the page now: Ca%27+Montini
  8. Sorry for the confusion. I am passing database values selected by the user to a results page, but when they get to the results page they are not seeing the database value they selected. It only shows the value up to the apostrophe. They select the option Ca'Montini which is in the database and then after they hit submit they go to the results page that only shows them Ca. It should be showing them the full word Ca'Montini which is the database value they selected.
  9. That didn't work On the results page I put the following code: <html> <head> <title></title> </head> <body> <?php $cat=$_POST['cat']; $subcat = mysql_real_escape_string($_POST['subcat']); echo $subcat; ?> </body> </html> The example I am using is this: When I go to search.php I select one of the objects in the first drop down box which determines what will be in the second drop down box. I then select the option i want from the second drop down box. I hit submit and I am taken to the search-results.php page. On this page I only want it to display $subcat. I am using these selections from the drop down boxes: first drop down box ($cat): Champagne second drop down box ($subcat): Ca'Montini Whats displayed on the search results page: Ca not sure if it is just because i am leaving the page or what, but have been working on this for quite a while.
  10. Kinda. $cat doesn't contain the string that I am refering to. It is actually the $subcat variable. The strange part is that within the drop down box on search.php it is displayed perfectly with no issues. Once you get to the results page is when the output for $subcat is jacked up. I read a little into the mysql_real_escape_string() you recommended, but I am having trouble figuring out where to put it within the code. Do I just put it on the results page or is it supposed to go on the search page? and where?
  11. I cannot get database content to display via an echo if the content of the database has an ' or " in it. Below is my code: search.php <?php $dbservertype='mysql'; $servername='localhost'; $dbusername='root'; $dbpassword='###'; $dbname='###'; connecttodb($servername,$dbname,$dbusername,$dbpassword); function connecttodb($servername,$dbname,$dbuser,$dbpassword) { global $link; $link=mysql_connect ("$servername","$dbuser","$dbpassword"); if(!$link){die("Could not connect to MySQL");} mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error()); } ?> <!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <title>Multiple drop down list box from plus2net</title> <SCRIPT language=JavaScript> function reload(form) { var val=form.cat.options[form.cat.options.selectedIndex].value; self.location='search.php?cat=' + val ; } </script> </head> <body> <?php @$cat=$_GET['cat']; if(strlen($cat) > 0 and !is_numeric($cat)){ echo "Data Error"; exit; } $quer2=mysql_query("SELECT DISTINCT product_categories_name, product_categories_id FROM tbl_product_categories"); if(isset($cat) and strlen($cat) > 0){ $quer=mysql_query("SELECT product_name, product_id, join_category_id, join_product_id FROM tbl_product, tbl_join_products_categories where join_category_id=$cat AND product_id=join_product_id order by product_name"); } echo "<form method=post name=f1 action='search-results.php'>"; echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>"; while($noticia2 = mysql_fetch_array($quer2)) { if($noticia2['product_categories_id']==@$cat){echo "<option selected value='$noticia2[product_categories_id]'>$noticia2[product_categories_name]</option>"."<BR>";} else{echo "<option value='$noticia2[product_categories_id]'>$noticia2[product_categories_name]</option>";} } echo "</select>"; echo "<select name='subcat'><option value=''>Select one</option>"; while($noticia = mysql_fetch_array($quer)) { echo "<option value='$noticia[product_name]'>$noticia[product_name]</option>"; } echo "</select>"; echo "<input type=submit value=Submit>"; echo "</form>"; ?> </body> </html> search-results.php <html> <head> <title></title> </head> <body> <?php $cat=$_POST['cat']; $subcat=$_POST['subcat'] echo $cat; echo $subcat; ?> </body> </html> HELP!!!!
  12. I did a bit of searching and found that this is a pretty well know IE bug, which I am sure you already knew about. IE will not allow you to hit enter to submit a form if there is only one input tag. I put the following in my submission form and it is working like a charm now. <input type="text" style="display: none;" disabled="disabled" size="1" />
  13. I was just hitting the enter key, but once I tried to actually click the submit button it does work and the row does display. Do you know how to get around that? having to click the button is a tough thing to ask the user.
  14. This is the one row I have in the database: name phone domain-name email comments completed XXXX Inc 7273680270 XXXX.com support@XXXX.com testing, testing, yes I don't see anything wrong with these entries. I also implemented your code suggestion and I am still having the same problem.
×
×
  • 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.