Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get ID from HTML form - PHP

Tags:

html

php

mysql

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

like image 262
Achilles Avatar asked Feb 17 '15 09:02

Achilles


People also ask

How can I get HTML id in PHP?

php $id = ((int)$_POST["id"]); .... Save this answer.

Can you give a form an id in HTML?

An id on a <form> tag assigns an identifier to the form. The identifier must be unique across the page.

What is id in HTML forms?

The id attribute specifies a unique id for an HTML element. The value of the id attribute must be unique within the HTML document. The id attribute is used to point to a specific style declaration in a style sheet. It is also used by JavaScript to access and manipulate the element with the specific id.

Can we use input tag without form?

Can you use input tag without form? Yes, you can have a valid input without a form.


1 Answers

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']

like image 89
serjoscha Avatar answered Sep 20 '22 15:09

serjoscha