Reputation: 504
I've a html form for get Id from visitor
<form action="show.php" method="post">
<p>Your id: <input type="text" name="id" /></p>
<p><input type="submit" /></p>
</form>
and the php file for act this .
<?php
$id = ((int)$_GET["id"]);
$con=mysql_connect('localhost','user','pass');
mysql_select_db('dbname',$con);
$query="SELECT * FROM `users` WHERE id = '$id'";
$select=mysql_query($query);
while($row=mysql_fetch_array($select)){
echo $row['name'];
}
mysql_close($con);
?>
but it's not working , can't read id , pelase help me for resolve this issue
Thank you
Upvotes: 5
Views: 18879
Reputation: 619
Your form is submitting data via POST so you have to accept it via POST method
<?php
$id = $_POST['id'];
?>
otherwise change the method to GET and write it like this
$id = ((int)$_GET["id"]);
Upvotes: 2
Reputation: 2785
Use POST intead of Get because use set post method for form.
$id = ((int)$_POST["id"]);
Upvotes: 3
Reputation: 3028
As you have used form method "post", id variable will be available in the global $_POST array so use:
<?php
$id = ((int)$_POST["id"]);
....
Upvotes: 4
Reputation: 520
You are submitting data via POST. Thats defined by the attribute "method" within your form tag:
<form action="show.php" method="post">
So data will not be stored in $_GET but in $_POST.
So to access the ID use $_POST['id'] not $_GET['id']
Upvotes: 8