jayNorth
jayNorth

Reputation: 63

how to pass the value field instead of the name field of a form to Mysql

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

Answers (2)

MrSnrub
MrSnrub

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

Dave Clarke
Dave Clarke

Reputation: 2696

You should use $_POST['IdArticle'] to retrieve the value of that hidden field.

Upvotes: 4

Related Questions