Reputation: 161
In the following form I want to post a variable, $getID, that holds the id of the user along with the rest of the information:
<?php
echo ="
<h3>What do you want to edit?</h3>
<form method='post' action='modifyrecord.php'>
<p>
Change:
<select name='getColumn'>
<option value='first_name'>First Name</option>
<option value='last_name'>Last Name</option>
<option value='email'>eMail</option>
<option value='gender'>Gender</option>
<option value='age'>Age</option>
<option value='comments'>Comments</option>
<option value='password'>Password</option>
</select>
To:
<input type='text' name='getValue'/>
</p>
</p><input type='submit' name='submit' value='modify this user'/></p>
</form>";
?>
Any help would be appreciated.
Upvotes: 1
Views: 847
Reputation: 290
In html you use a hidden field to pass data that you do not want exposed to the end user so:-
<input type='hidden' name='getID' value=$getID />
Upvotes: 1
Reputation: 7093
First of all, let's fix your code by removing unnecessary symbol =
. Or perhaps it's better for you to use just plain HTML code instead of using echo
?
echo "
<h3>What do you want to edit?</h3>
<form method='post' action='modifyrecord.php'>
<p>
Change:
<select name='getColumn'>
<option value='first_name'>First Name</option>
<option value='last_name'>Last Name</option>
<option value='email'>eMail</option>
<option value='gender'>Gender</option>
<option value='age'>Age</option>
<option value='comments'>Comments</option>
<option value='password'>Password</option>
</select>
To:
<input type='text' name='getValue'/>
</p>
</p><input type='submit' name='submit' value='modify this user'/></p>
</form>";
I strongly not recommending to use ID
in HTML form because user can use DEV tools that is available in probably all browsers. Since you shouldn't pass ID in any way, how can you retrieve one during POST method?
My answer: in the same way you retrieved ID in current page with form (probably with function or class method). It is much safer thing as user will not be able to tamper vital data such as ID
.
I don't see any reason why my suggestion is wrong compared to your intention, if there is, please let me know.
Upvotes: 1