Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Feb 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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'].'');
    ?>

  • #2
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    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


    Last edited by student101; 02-12-2013 at 06:23 AM.
    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •