0

Hey so Im pretty new to PHP/HTML but In my code below I have No Errors. I read from a database server perform proper query then Store my data from the query in a Combobox aka list. I want to be able to obtain the value of the item the user selects. But i end up getting nothing. I attempt to check this by typing :

echo $search;?>
<br>First shift Super:
<select name="search"> <!-- COMBO Box -->
<?php foreach($data as $i=>$rows): ?>
    <!-- AMOUNT(PROID), THEN FILL WITH THE CONTENT(PRONAME)-->
    <option value="<?=$rows['PROID']?>"><?=$rows['PRODNAME']?></option>
<?php endforeach; ?>
</select>
<!-- TESTING For getting selected value BELOW-->
<?php $search = $_POST['search'];//$search holds the selected value? 
echo $search;  //Nothing appears
$query2 = "SELECT * FROM PRODUCTS WHERE PRODNAME = '$search'";
$stid2 = oci_parse($dot, $query2); //turns this into something database can understand
oci_execute($stid2);//executes the query
$data2 = array();
//$length equals the # of rows/Tuples returned by query
//oci_fetch_all stores database info into $data
$length2 = oci_fetch_all($stid2, $data2, null, null, OCI_FETCHSTATEMENT_BY_ROW);
//http://php.net/manual/en/function.oci-fetch-all.php
$firstRow = $data2[0];//now holds data from table?>
<!-- TESTING For getting selected value ABOVE-->
Phone #: <input type='phone' name='phone'></br>
<br> On Call:<select name="name"> <!-- COMBO Box -->
<?php foreach($data2 as $i=>$rows): //PRODNAME Display is EMPTY ?>
<!-- AMOUNT(PROID), THEN FILL WITH THE CONTENT(PRONAME)-->
    <option value="<?=$rows['PROID']?>"><?=$rows['PRODNAME']?></option>
<?php endforeach; ?>
</select>
Peyman Mohamadpour
  • 17,954
  • 24
  • 89
  • 100
n00bie1221
  • 35
  • 1
  • 1
  • 6
  • 3
    PHP being server side will only show you values that have been sent to it (by submitting a form with the select for example) – Dror Oct 20 '16 at 22:36
  • So how would I get that value? I need that value to run my next query. – n00bie1221 Oct 20 '16 at 22:41
  • 1
    Either submit the form, or learn how to use AJAX. – Barmar Oct 20 '16 at 23:00
  • @Barmar could you direct me towards references about how to submit the form. – n00bie1221 Oct 20 '16 at 23:03
  • Any tutorial on using PHP to process web forms should explain it. `
    ` will send all the input fields to `scriptname.php` when the user clicks on the submit button.
    – Barmar Oct 20 '16 at 23:04
  • If you want to submit the form without the user clicking on the submit button, you need to learn Javascript. – Barmar Oct 20 '16 at 23:04
  • @Barmar Thanks, under what subject should I research under Javascript? – n00bie1221 Oct 20 '16 at 23:07
  • Search for something like submit form when select from menu – Barmar Oct 20 '16 at 23:11
  • 1
    You are open to SQL injections. You should bind that user input, see http://php.net/manual/en/function.oci-parse.php. – chris85 Oct 20 '16 at 23:13
  • @Barmar Thanks..no idea you need to know 5 languages to write a simple website(HTML,MYSQL, PHP, CSS, and Javascript) – n00bie1221 Oct 20 '16 at 23:14
  • Yep. Web pages use a number of different technologies. – Barmar Oct 20 '16 at 23:15
  • @Barmar but keep in mind I want the value of what the user selects to use for my query...if I use a button, wont that just send the value to another .php or .js? Is what I am asking to do impossible? – n00bie1221 Oct 20 '16 at 23:20
  • It should send the value and then await for response of that page, so you process and return the data as needed. https://learn.jquery.com/ajax/ – chris85 Oct 21 '16 at 00:02
  • @chris Okay i will look into Javascript, i never used it or know how it works, but if it will allow me to get the value of the user selection then i will figure it out – n00bie1221 Oct 21 '16 at 00:13
  • Possible duplicate of http://stackoverflow.com/questions/15777455/get-value-from-combobox-in-php?rq=1 – jaggedsoft Oct 24 '16 at 02:30

1 Answers1

0

i ended Up using $search=$_POST["search] now my selected value is being stored into $search upon the click of a button.

n00bie1221
  • 35
  • 1
  • 1
  • 6
  • Your question/code doesn't even indicate your form is being posted. This question is not useful to other readers – jaggedsoft Oct 24 '16 at 02:28