0

What I would like to do is find a way to "hide" the option value listing from the page source if possible.

I have successfully created a page with multiple drop downs (6 now, will be 15+ in total); database queries are working, drop downs are working, posting selections and results are visible in a separate processing page, HOWEVER; The option values are showing in the page source.

Page Design (for this example) test.php - contains db connect (will change that to separate include_once later), queries, option values code, and table data. index.php - contains only an include statement calling test.php.

Running test.php in a browser exposes queries (which I don't want) and loading the index that is including test.php hides queries, but shows options which I prefer not to have. I have searched everywhere (maybe I am not asking the question properly) and have tried to run the sql in one page and posted the result to another, but I cannot get it to work.

What I wanted to do: Run MySQL queries in a separate "function" page and then call the output (select name) to another (HTML) page and embed the dropdowns into a cell of a table.

Questions:

  1. Is it possible to hide the option values in the index.php page?
  2. Is this my design flaw and if so, what is a better way?tem
  3. How do I run queries in one page, and then call the output of that query as a drop down into an HTML page?

test.php (Shortened example)

    <!--mo-->
<td colspan="2"><div align="right"><font face="Arial, Helvetica, sans-serif"> 
<?php
$query = "SELECT date_code_mo, date_code_mo_desc FROM tbl_gm_assy_date_code_mo ORDER BY           date_code_mo ASC";
echo '<select name="date_mo">';
if ($result = mysqli_query($link, $query)) {
while ($row = mysqli_fetch_assoc($result)) {
echo '<option value="' . $row['date_code_mo_desc'] . '">' . $row['date_code_mo'] . '</option>';      
}
mysqli_free_result($result);
}
echo '</select>';
?>
</font></div></td>
<!--week-->
<td colspan="2"><div align="left"><font face="Arial, Helvetica, sans-serif"> 
<?php
$query = "SELECT date_code_wk, date_code_wk_desc FROM tbl_gm_assy_date_code_wk ORDER BY     date_code_wk ASC";
echo '<select name="date_wk">';
if ($result = mysqli_query($link, $query)) {    
while ($row = mysqli_fetch_assoc($result)) {
echo '<option value="' . $row['date_code_wk_desc'] . '">' . $row['date_code_wk'] . '</option>';
}
mysqli_free_result($result);
}
 echo '</select>';
 ?>

index.php source (table definitions not shown)

<select name="date_mo"><option value="Janurary">01</option><option value="Feburary">02</option><option value="March">03</option><option value="April">04</option><option value="May">05</option><option value="June">06</option><option value="July">07</option><option value="August">08</option><option value="September">09</option><option value="October">10</option><option value="November">11</option><option value="December">12</option></select>

<select name="date_wk"><option value="First">A</option><option value="Second">B</option><option value="Third">C</option><option value="Fourth">D</option><option value="Fifth">E</option></select> 

I have used a lot of examples available on here to get this far, and I am sure it is something small that has been missed, regardless, THANKS TO YOU ALL!

user3019140
  • 9
  • 1
  • 6

2 Answers2

0

I'm not sure if I understand your question..

1) I don't understand why you are worried about option values in the page source, they are simply a value send to the server. Where they are interpreted and get their meaning. You can change them to anything you want. Only the client side code (where the option tags appear) is visible for the user, the serverside code is not visible for the user. --> the user can see the values of the option tags, but has no idea what you are going to do with them serverside.

2) see 1)

3) when submitting a form, the values are send to the url specified with the action attribute:

<form action="evaluate.php"  method="post">
  ...
</form>

The output of evaluate.php will be send to the client --> this is the next page the user will see. For the syntax to form dropdown menu's check here: Pre-filling select tags from array

For retrieving the values send, have a look at the:

$_GET['varname'] or $_POST['varname'] arrays. Depending on the method specified in the form tag, the values send are stored here.

Where varname = the name attirbute of the form element. Depending on the type of the formelement it is more or less trivial to extract the values. There are plenty of tutorials arround and very easy to find.

I also recommend having a look at the following topic: How can I prevent SQL injection in PHP?

Community
  • 1
  • 1
cytofu
  • 873
  • 9
  • 17
  • The only reason I was thinking that the code would be cleaner, but your suggestions are appreciated. I will continue on and thanks for the SQL Injection suggestion. – user3019140 Nov 22 '13 at 21:15
0

You're looking for cascading dropdowns, it's the best way to manage it in your case. This question is already answered here:

How to make a Cascading Drop Down List in PHP using jQuery

It uses a classic example of selecting cities based on a selected country, but you can easily adjust it for yourself, by adding .change() function for all of your dropdowns except the last one and adding a php script that returns the right list.

There's also a plugin for JQuery, if you want to check it out:

jQuery Cascading Dropdown Plugin

Community
  • 1
  • 1
Ulugbek
  • 164
  • 1
  • 8
  • Yeah it is starting to look like I have to use cascade. Is there a good video tutorial somewhere? There are a few on YouTube but I wonder of there are some better ones... – user3019140 Nov 25 '13 at 01:51
  • The problem is that the examples I see are using straight HTML coding and I am not doing that. I am using MySQL and PHP to create the select boxes, that is where I get lost. – user3019140 Nov 25 '13 at 03:44
  • Not sure about videos, but there are quite a lot of resources describing in detail how it's done with PHP and MySQL. See if this helps: [How to create chained select with php and jquery](http://www.yourinspirationweb.com/en/how-to-create-chained-select-with-php-and-jquery/) – Ulugbek Nov 25 '13 at 06:02
  • Thanks, I had a quick scan of it and I will try that one out. I found a video that was really helpful but only to a point. The one you list has more than one table which is a good start. Cheers! – user3019140 Nov 25 '13 at 18:45