1

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.

2
  • I did it with the following code: <input type='hidden' name='id' value='<?php echo $getID; ?>'> Commented Oct 15, 2016 at 16:11
  • That is very not recommended. User can freely change its value. Why don't you just assign to a variable during POST method? EDIT: your code is also invalid. Commented Oct 15, 2016 at 16:13

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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 />

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.