Jump to content

How to retrieve php textbox value to be used with mysql


suneetp

Recommended Posts

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.

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">

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.