svalding Posted March 27, 2008 Share Posted March 27, 2008 Hey, I just started developing in php and am in need of some help. I have a webpage built for a cellphone inventory application. Information such as the name of the user, make and model of phone, sim card number, and imei number are all stored in a mysql database. In the code I have a query defined that populates a drop down menu from the mysql database. That piece works fantastically. What I am having problems with is getting the selected value of the menu stored to a variable so that I can run another query based on the selected value to post the rest of the information about the user in a table as follows: username {submit button} Cellphone number: [need data put here] Cellphone make: [need data put here] IMEI number: [need data here] SIM number:[need data here] Right now the page is set up with <form action="inventory.php" //same page // method="GET" //so that it puts info in URL//</form> Link to comment https://forums.phpfreaks.com/topic/98202-php-form-help/ Share on other sites More sharing options...
MadTechie Posted March 27, 2008 Share Posted March 27, 2008 can you post the code ? Link to comment https://forums.phpfreaks.com/topic/98202-php-form-help/#findComment-502479 Share on other sites More sharing options...
svalding Posted March 27, 2008 Author Share Posted March 27, 2008 <?php include getinfo.php; # Main connection information $db_host='localhost'; $db_database='cellphone'; $db_username='******'; $db_password='********'; $connection = mysql_connect($db_host,$db_username,$db_password); if (!$connection) { die ("Could not connect to database using supplied credentials"); } $db_select = mysql_select_db($db_database); if (!$db_select) { die ("Could not select database"); } # Main query to populate the drop-down list $query = "SELECT name FROM inventory ORDER BY name"; $query2 = "SELECT make,model,number,ime,sim FROM inventory"; $result = mysql_query($query); if (!$result) { die("Query execution problem: " . msql_error()); } $result2 = mysql_query($query2); $row = mysql_fetch_assoc($result, $query2); $number = mysql_numrows($result); echo ' <html> <head> <title>Dover Chemical Cellphone Inventory System</title> </head> <body> <!-- create a table for the header banner --> <table bgcolor="00619e" height="150" width="100%"> <tr> <td align="center"><font color="white" size="+24">Dover Chemical Cellphone Inventory</font></td> </tr> <!-- close banner table --> </table> <hr width=50%></hr> <center> <table> <tr> <td><p> Account Number: <b>994861915 </b>| Password: <b>popularscience</b> | Call : <b>1-800-331-0500</b></p></td> </tr> </table> </center> <hr width=50%></hr> <!-- I stole this code from the dover website for whitespace, editing the table for height. Thanks Mr. Harr!!!! --> <table height="16%"> <tr> <td> <font color=#ffffff> --------- --------- --------- --------- --------- --------- --------- --------- </font> </td> </tr> </table> <!-- center it all up in one fell swoop! --> <div align="center"> <!-- now we need a table to place the form in --> <table> <!-- form used to select the appropriate user --> <form action="inventory.php" method="GET"> <?php <label>Select a user:</label> <select name="username" id="name"> <option value="">Select a user</option>'; for($i=0; $i<$number; $i++) { $name = mysql_result($result,$i,"name"); echo '<option value="'; echo $row[name]; echo '"'; if($selectedname==$row[name]) echo " selected"; echo '>'; echo "$name"; } echo '</option>'; /* This section builds the queries and gets the data for each criteria in the table, not sure if I need to do this much or not $getphoneinfo = "SELECT make,model FROM inventory WHERE name LIKE '$selectedname'"; $getphonenumber = "SELECT number FROM inventory WHERE name LIKE '$selectedname'"; $imei = "SELECT imei FROM inventory WHERE name LIKE '$selectedname'"; $sim = "SELECT sim FROM inventory WHERE name LIKE '$selectedname'"; $phone_query = mysql_query($getphoneinfo); $number_query = mysql_query($getphonenumber); $imei_query = mysql_query($imei); $sim_query = mysql_query($sim); $phone_result = mysql_result($phone_query); $number_result = mysql_result($number_query); $imei_result = mysql_result($imei_query); $sim_result = mysql_result($sim_query); $number_phone = mysql_numrows($phone_query); $number_number= mysql_numrows($number_query); $number_imei = mysql_numrows($imei_query); $number_sim = mysql_numrows($sim_query); */ echo ' <input type="Submit" value="Get info"> </form> <!-- done with the form piece --> <!-- now we close the container --> </table>'; echo ' <!-- now we need a table to put the various information about the users phone --> <br /> <br /> <table align="center" width="30%" height="20%"> <tr> <td>Cellphone model</td><td>'; echo $phone_result; echo '</td> </tr> <tr> <td>Cellphone number</td><td>'; echo "blank" ; echo '</td> </tr> <tr> <td>IMEI number</td><td>'; echo "blank"; echo '</td> </tr> <tr> <td>SIM number</td><td>'; echo "blank"; echo '</td> </tr> <!-- close information table --> </table> </div> <!-- poor mans whitespace, not as cool as brians --> <br /> <br /> <br /> <!-- Copyright mumbo-jumbo...gotta cover your ass now adays --> <center><font size="-14" face="papyrus">Copyright © 2008 Dover Chemical Corporation</font></center> </body> </html> '; mysql_close(); ?> Link to comment https://forums.phpfreaks.com/topic/98202-php-form-help/#findComment-502484 Share on other sites More sharing options...
MadTechie Posted March 27, 2008 Share Posted March 27, 2008 //...Snip <label>Select a user:</label> <select name="username" id="name"> <option value="">Select a user</option>'; for($i=0; $i<$number; $i++) { $name = mysql_result($result,$i,"name"); echo '<option value="'; echo $row[name]; echo '"'; if($selectedname==$row[name]) echo " selected"; echo '>'; echo "$name"; } echo '</option>'; //******Add the line below $selectedname = $_GET['username']; echo "Selected users - $selectedname";// debug info /* This section builds the queries and gets the data for each criteria in the table, not sure if I need to do this much or not $getphoneinfo = "SELECT make,model FROM inventory WHERE name LIKE '$selectedname'"; //...Snip Link to comment https://forums.phpfreaks.com/topic/98202-php-form-help/#findComment-502491 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.