I3erk Posted April 27, 2011 Share Posted April 27, 2011 I am quite new to web programming and i am trying to make a ComboBox for my website. I have looked online, but i was unable to find anything on how to do this. This ComboBox will be on a promo page for the website. Right now, i created the ComboBox and it works perfectly. The next thing i want to do are 2 things (and have them done simultaneously): 1. when the submit button is clicked, i want it to store whatever is selected in the ComboBox into a database/spreadsheet, in order to determine the number of times the option is selected. 2. when the submit button is clicked, the client will then get sent to the website homepage. Can anyone point me in the right direction as to how i can go about doing this? Thanks. I3erk <form id="form1" name="form1" method="post" action="http://www.maisonsbellevue.com"> <select name="frmhowhear" id="frmhowhear"> <option value="">Select one…</option> <option value="Courrier Laval">Courrier Laval</option> <option value="L'Étoile">L'Étoile</option> <option value="Le Progress">Le Progress</option> <option value="Le Richelieu">Le Richelieu</option> <option value="Le Mirabel">Le Mirabel</option> <option value="L'Information du Nord">L'Information du Nord</option> <option value="Le Regional">Le Regional</option> <option value="The Gazette">The Gazette</option> <option value="Tremblant Express">Tremblant Express</option> <option value="La Flèche">La Flèche</option> <option value="Brochure">Brochure</option> <option value="Recommendation">Recommendation</option> </select> Quote Link to comment https://forums.phpfreaks.com/topic/234853-help-please-how-do-i-store-data-from-a-combobox/ Share on other sites More sharing options...
kney Posted April 27, 2011 Share Posted April 27, 2011 $_POST['frmhowhear'] should get you the value of ur combobox Quote Link to comment https://forums.phpfreaks.com/topic/234853-help-please-how-do-i-store-data-from-a-combobox/#findComment-1206885 Share on other sites More sharing options...
I3erk Posted April 27, 2011 Author Share Posted April 27, 2011 would that still retrieve the value even if it is a different page? or does it have to be on the same page as the combobox Quote Link to comment https://forums.phpfreaks.com/topic/234853-help-please-how-do-i-store-data-from-a-combobox/#findComment-1206888 Share on other sites More sharing options...
kney Posted April 27, 2011 Share Posted April 27, 2011 It has to be on the same page: If you want to use it on another page use: <?php $_SESSION['WhateverNameYouLike'] = $_POST['frmhowhear']; ?> But you got to remember to use <?php session_start(); ?> on each page u use the session variable And to redirect to another page use this <?php if (isset($_POST['WhateverYourButtonsNameIs'])) { header('Location: http://www.example.com/'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/234853-help-please-how-do-i-store-data-from-a-combobox/#findComment-1206893 Share on other sites More sharing options...
I3erk Posted April 27, 2011 Author Share Posted April 27, 2011 Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/234853-help-please-how-do-i-store-data-from-a-combobox/#findComment-1206899 Share on other sites More sharing options...
hyster Posted April 27, 2011 Share Posted April 27, 2011 there are 3 ways i no of to send data from 1 page to anouther _post _get sessions since u have a form _post will work fine for u change <form id="form1" name="form1" method="post" action="http://www.maisonsbellevue.com"> to <form id="form1" name="form1" method="post" action="http://www.maisonsbellevue.com/test.php"> this will echo the value selected. u just need to create a mysql table and run an insert query. test.php <?php $var = $_POST['frmhowhear']; echo $var ; ?> Quote Link to comment https://forums.phpfreaks.com/topic/234853-help-please-how-do-i-store-data-from-a-combobox/#findComment-1206915 Share on other sites More sharing options...
I3erk Posted April 27, 2011 Author Share Posted April 27, 2011 Hyster, if i change <form id="form1" name="form1" method="post" action="http://www.maisonsbellevue.com"> to <form id="form1" name="form1" method="post" action="http://www.maisonsbellevue.com/test.php"> Wont it take the clients to the test.php page instead of sending them to the homepage upon clicking the submit button? Is there a way to do both? (ie: have 2 actions for 1 button, such as storing the selected option into a table on a new page, while still sending the client to the website homepage) Quote Link to comment https://forums.phpfreaks.com/topic/234853-help-please-how-do-i-store-data-from-a-combobox/#findComment-1206922 Share on other sites More sharing options...
hyster Posted April 27, 2011 Share Posted April 27, 2011 ys it will. try this. <form id="form1" name="form1" method="get" action="http://www.maisonsbellevue.com/home_page.php"> and further down <?php if (isset($_GET['frmhowhear'])) { echo $_GET['frmhowhear']; // replace this with the sql query } ?> Quote Link to comment https://forums.phpfreaks.com/topic/234853-help-please-how-do-i-store-data-from-a-combobox/#findComment-1206939 Share on other sites More sharing options...
hyster Posted April 27, 2011 Share Posted April 27, 2011 not tested this but i dont think it will be far wrong <form id="form1" name="form1" method="get" action="http://www.maisonsbellevue.com/index.php"> <select name="frmhowhear" id="frmhowhear"> <option value="">Select one…</option> <option value="Courrier Laval">Courrier Laval</option> <option value="L'Étoile">L'Étoile</option> <option value="Le Progress">Le Progress</option> <option value="Le Richelieu">Le Richelieu</option> <option value="Le Mirabel">Le Mirabel</option> <option value="L'Information du Nord">L'Information du Nord</option> <option value="Le Regional">Le Regional</option> <option value="The Gazette">The Gazette</option> <option value="Tremblant Express">Tremblant Express</option> <option value="La Flèche">La Flèche</option> <option value="Brochure">Brochure</option> <option value="Recommendation">Recommendation</option> </select> <input type="submit"/> </form> <?php //database connection info $host="localhost"; // Host name $username="username"; // Mysql username $password="password"; // Mysql password // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("table_name")or die("cannot select DB"); if (isset($_GET['frmhowhear'])) { $var = $_GET['frmhowhear']; // update data in mysql database $sql="INSERT INTO $tbl_name (rsku) values ('$var')"; $result=mysql_query($sql); // if successfully updated. but dont need it if($result){ echo "Update Successful"; } else { echo "ERROR"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/234853-help-please-how-do-i-store-data-from-a-combobox/#findComment-1206957 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.