suneetp Posted March 15, 2015 Share Posted March 15, 2015 Php value which was assigned to a text box, how to get this value to be used further with mysql query. Pls help me with the code Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted March 15, 2015 Share Posted March 15, 2015 The values from a text field once a form has been submitted will be contain within the $_GET or $_POST superglobal variable. You may find these pages useful http://php.net/manual/en/tutorial.forms.php http://php.net/manual/en/language.variables.external.php When using these variables in your SQL queries make sure you sanitize it, eg mysqli_real_escape_string or use prepared queries. Quote Link to comment Share on other sites More sharing options...
suneetp Posted March 15, 2015 Author Share Posted March 15, 2015 (edited) Thanks for replying. My query is not getting the value once the form is submitted. Let my explain you using the code i have written : Step 1. I have a dropdown and using jQuery I am picking up the selected item and display the selected text in the textbox. Step 2. Once this is accomplished, sql query will run thereby display the list of records in the table just below the drop down. Code for Step 1 <select id="ddl_pay"> <option value="-1">---- Selection ----</option> <option value="Paid">Paid</option> <option value="UnPaid">UnPaid</option> </select> <script> $("#ddl_pay").change(function (e) { e.preventDefault(); var a = $("#ddl_pay option:selected").text(); if (a == "---- Selection ----") { exit; } else { document.getElementById("sel").value = a; } }); </script> Code for Step 2 [ Query to display records in the table ] <?php //$_POST['seltext'] = "UnPaid"; if (isset($_REQUEST['a'])) { $val = $_REQUEST['a']; } if (isset($_GET['a'])) { $val = $_GET['a']; } if(!empty($val)){ if ($val == 'UnPaid') { $getrecs = "SELECT u.t_ordid, DATE_FORMAT(u.tord_dt,'%d-%m-%Y') as label_date, c.u_name, s.stat_desc FROM utmp_orders as u join user_dtls as c on c.user_id=u.user_id join status as s on s.stat_cd=u.stat_cd WHERE u.pay_flag='N'"; $retrv = mysqli_query($connection, $getrecs); }else if ($val == 'Paid') { $getrecs = "SELECT u.t_ordid, DATE_FORMAT(u.tord_dt,'%d-%m-%Y') as label_date, c.u_name, s.stat_desc FROM utmp_orders as u join user_dtls as c on c.user_id=u.user_id join status as s on s.stat_cd=u.stat_cd WHERE u.pay_flag='Y'"; $retrv = mysqli_query($connection, $getrecs); } else{ $retrv="";} } ?> In the above code, you see "//$_POST['seltext'] = "UnPaid";" this line checks that once the value is pass, all records are populated in the table. Above code is working but the value of the textbox is blank, ie using inspect element it is showing : <input type="text" id="sel" name="seltext" value style="width:50px"> Edited March 15, 2015 by suneetp Quote Link to comment Share on other sites More sharing options...
iarp Posted March 15, 2015 Share Posted March 15, 2015 Your <select> is missing a name="". All elements on a form require a name="" if you wish to use the data when they hit submit. As well I do not see the text field that you're talking about in your code. Quote Link to comment Share on other sites More sharing options...
suneetp Posted March 15, 2015 Author Share Posted March 15, 2015 yeah sorry i missed that. Here is the text field : <input type="text" id="sel" name="seltext" value="" style="width:50px" /> Quote Link to comment Share on other sites More sharing options...
suneetp Posted March 15, 2015 Author Share Posted March 15, 2015 Here is the screenshot of the output : Quote Link to comment Share on other sites More sharing options...
iarp Posted March 15, 2015 Share Posted March 15, 2015 You can access that <inputs> value by either $_GET['seltext'] or $_POST['seltext'] . I would not use $_REQUEST. The other option would be to do away with the scripting, give the <select> a name="" and then access that via $_GET or $_POST Quote Link to comment 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.