ericjw316 Posted September 15, 2015 Share Posted September 15, 2015 Here is what i am trying to do. I have a client that wants to submit a form but he may need to go back and change one of the forms enterys. I set up the sql to pull the items that will view in a drop down. What i need to figure out is how to pass the id to another page and add that to the sql select * from table where id = (item selected in previous page) Then i need to display the the data into a form with text boxes and check boxes. If you can help me out with this i would appricate it. If you would like to see the demo of what i have done let me know and i can give you the url link to view everything and give some of the code. Thank you to anyone that can help me. Quote Link to comment https://forums.phpfreaks.com/topic/298175-help-with-php-mysql-and-multiple-pages/ Share on other sites More sharing options...
secweb Posted September 15, 2015 Share Posted September 15, 2015 You could use a hidden form input element for the id. As for the pre-filled data, where are you storing it anyway, i.e. you'd get it from there... Otherwise if they use a back button then encode it in that (maybe better to use an actual button in that case), however if they don't use your pre-formatted back link then the data is lost, so you may want to store it in session variables, however they'll only be able to fill out one form at once then (which is what MOST people will do anyway, but there's always one) Quote Link to comment https://forums.phpfreaks.com/topic/298175-help-with-php-mysql-and-multiple-pages/#findComment-1520869 Share on other sites More sharing options...
ericjw316 Posted September 15, 2015 Author Share Posted September 15, 2015 (edited) After doing some more research i think what i need is a session to pass the ID to the next page and put that into the sql code. If you know of a way to do that i am hoping someone can either direct me to an example or give me the code to pass that on. So what i need is the session to pass what is selected from a drop down and than to be put into the sql get to display the proper info on the form. I need this as i will have thousands of enterys into the table but need to select 1 to display on the form. Edited September 15, 2015 by ericjw316 Quote Link to comment https://forums.phpfreaks.com/topic/298175-help-with-php-mysql-and-multiple-pages/#findComment-1520914 Share on other sites More sharing options...
secweb Posted September 15, 2015 Share Posted September 15, 2015 And what code do you have? Quote Link to comment https://forums.phpfreaks.com/topic/298175-help-with-php-mysql-and-multiple-pages/#findComment-1520917 Share on other sites More sharing options...
ericjw316 Posted October 2, 2015 Author Share Posted October 2, 2015 Here is what i am trying to do. I have a dropdown (and or excel type look) that i need to pull data from the database. When i have an item selected i need to pass the info to the next page via a session. I have the drop down pulling from the database but i need to list Name and address in the dropdown. If this is not possible i can do a list of items from a search but i will need to make the id a link to pass the id to the next page where i need to build a report.If you can give me some info on this i would appreciate it.Ehere is what i have for code on the dropdown <?php // declare database connection variables. $host = "localhost"; $username = "root"; $password = ""; $db_name = "sample"; $tbl_name = "tbl_report"; // connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql = "SELECT id, name, address FROM $tbl_name"; $result = mysql_query($sql) or die(mysql_error()); $dropdown = "<form action='report.php' method='post'>"; $dropdown .= "<select name='items' class='select'>"; while ($row = mysql_fetch_assoc($result)) { $dropdown .= "\r\n<option value='{$row['type']}'>{$row['type']}</option>"; } $dropdown .= "\r\n</select>"; $dropdown .= "<input type='submit' name='submit' value='Submit'>"; $dropdown .= "</form>"; //closing the form tag echo $dropdown; ?> What i need to do is pass both the name and address to the drop down and in the value show the id. I need to pass the id to the next page which is report.php and there will be another sql that will run and get the info for the id and then pass to all the fields that i have on that page. I dont know how to set up the session for the id to follow. This is where i am getting confused. Quote Link to comment https://forums.phpfreaks.com/topic/298175-help-with-php-mysql-and-multiple-pages/#findComment-1522131 Share on other sites More sharing options...
scootstah Posted October 2, 2015 Share Posted October 2, 2015 Put the id as the option value. $dropdown .= "\r\n<option value='{$row['id']}'>{$row['type']}</option>";Then on "report.php" you can get the id from the $_POST variable. $id = $_POST['items'] Quote Link to comment https://forums.phpfreaks.com/topic/298175-help-with-php-mysql-and-multiple-pages/#findComment-1522134 Share on other sites More sharing options...
maxxd Posted October 2, 2015 Share Posted October 2, 2015 scootstah's right - there's no need to use sessions here. In fact, if the session value is going to be set when the user selects an option from the drop-down, using a session is going to make it more difficult on you. Simply change while ($row = mysql_fetch_assoc($result)) { $dropdown .= "\r\n<option value='{$row['type']}'>{$row['type']}</option>"; } to while ($row = mysql_fetch_assoc($result)) { $dropdown .= "\r\n<option value='{$row['type']}'>{$row['name']} :: {$row['address']}</option>"; } Then, on page report.php, use $selectedID = $_POST['items'] as suggested. Note that this ($selectedID) will then contain the 'value' attribute of the option item (in this case, your desired 'id' from the database), not what the user sees in the drop-down itself. It goes without saying that you need to sanitize any data before doing anything with it in relation to a database, and that you are going to have to move to PDO or MySQLi soon - the msql_* functions are deprecated and will be removed in the next version of php. Quote Link to comment https://forums.phpfreaks.com/topic/298175-help-with-php-mysql-and-multiple-pages/#findComment-1522143 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.