Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-10-2013, 02:46 PM   PM User | #1
GuardPH
New to the CF scene

 
Join Date: Feb 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
GuardPH is an unknown quantity at this point
How to Get the ID variable of input type txt

Hi... I need to get the ID variable of DropDown form then pass it to result.php - But I can't get to make it work... Help!

main.php
Code:
<script>
<?php
$user = $_GET["user"];
?>
 $(document).ready(function(){
	var user = '<?php echo $user ;?>';
  $("#tag").autocomplete('/find/autocomplete.php?user='+user, 
  {
        selectFirst: true
  });
 });
</script>

<form method="post" action="result.php">
<input style="padding:2px 5px 2px 5px;font-family:verdana;font-size:11px;color:#444444" name="tag" type="text" id="tag" size="50"/>
<INPUT type="submit" value="Submit" style="background-color:grey; font-family: verdana; font-size: 10px; color:#fff;">
</form>
autocomplete.php --- This will Populate the dropdown [id] [company]
Code:
<?php
	
	$q=$_GET['q'];
	$user = $_GET['user']; 
	$my_data=mysql_real_escape_string($q);
	$mysqli=mysqli_connect('localhost','root','root101','uaeexchange') or die("Database Error");
	$sql="SELECT comp_name,id FROM viewreport2 WHERE user='$user' AND comp_name LIKE '%$my_data%' ORDER BY comp_name";
	$result = mysqli_query($mysqli,$sql) or die(mysqli_error());
	
	if($result)
	{
		while($row=mysqli_fetch_array($result))
		{
			echo "[".$row['id']."]  ".$row['comp_name']."\n";
		}
		
		
	}
	
?>
result.php - this will redirect back to main page.
Code:
<?php

if(isset($_POST['Submit']))
	{ 	
    $id = $_GET['tag'];
    $user = $_GET['user'];
	}
//	header("Location: http://localhost/crmview.php?id=".$id."?T1=".$text);
header('Location: main.php?id='.$_POST['id'].'&user='.$_POST['user'].'');
?>
GuardPH is offline   Reply With Quote
Old 02-12-2013, 06:21 AM   PM User | #2
student101
Regular Coder

 
student101's Avatar
 
Join Date: Nov 2007
Posts: 610
Thanks: 80
Thanked 13 Times in 13 Posts
student101 is on a distinguished road
Quote:
Originally Posted by GuardPH View Post
Hi... I need to get the ID variable of DropDown form then pass it to result.php - But I can't get to make it work... Help!
Your form is $_POST(ing) but you using $_GET ?

<form method="post" action="result.php">
$id = $_GET['tag'];

try
Code:
$id = $_POST['tag'];
... & so on
Try this too


__________________
Thanks for your support!
Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

Give thanks & resolve when done :thumbsup:

Last edited by student101; 02-12-2013 at 06:23 AM..
student101 is offline   Reply With Quote
Old 02-12-2013, 01:45 PM   PM User | #3
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
They've complicated it by writing ajax and assuming that has something to do with PHP.
Input Id's are not provided to PHP as HTML doesn't consider them values upon success. Autocomplete.php will only have access to $_GET['user'] since the JS doesn't provide it with any other value. Result.php cannot read $_GET['user'] nor $_GET['tag'] as neither are provided. You will find a $_POST['tag'], but no corresponding user offset.
Choose either GET or POST method and stick with it for every step. If you use GET, than you can add the user to the form action as a querystring. If you choose post and don't want to mix get, than you can pass it to the form as a hidden input. IMO it'd be easier to do this and use the JS to iterate the field's within the form to build its post request.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:07 AM.


Advertisement
Log in to turn off these ads.