Reputation: 63
Hello,
I'm trying to pass the value of the value field to a Mysql database.
<input type="hidden" name="IdArticle" value='<?php echo $IdArticle; ?>' />
For the Mysql command if I Use
$_POST['IdArticle']
then it will return "IdArticle". But I want to get $IdArticle of the value field returned
How would I retrieve the parameter of the value field? I want to do this in order to get different values from the $IdArticle variable each time the form is submitted. thanks in advance for your help.
Upvotes: 1
Views: 73
Reputation: 1183
You can use the field like this in MySQL querys:
// Get parameter as integer:
$idArticle = 0;
if (isset($_POST['idArticle'])) $idArticle = ((int) $_POST['idArticle']);
// Build MySQL query:
$query = "SELECT * FROM ARTICLES WHERE ID = '" . $idArticle . "'";
$result = mysql_query($query);
// ...
The example code will default to ID 0 if no ID parameter is given.
Please keep in mind that SQL query inputs have to be escaped if they are Strings at not pure Integers. In this case, the parameter is converted into an Integer. If you use Strings, you have to use mysql_real_escape_string
. Otherwise, your application will become vulnerable to SQL injections.
Upvotes: 0
Reputation: 2696
You should use $_POST['IdArticle']
to retrieve the value of that hidden field.
Upvotes: 4