Jump to content

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

Edited by suneetp

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.