Reputation: 349
Can anyone see an issue that would prevent this code from not posting the 'id1' text box to the 'updateUser.php' page? I've been sitting her staring at this for 30 minutes and can not for the life of me figure out what is wrong, for toubleshooting, I have it echoing on the other side and $newUser and $username have the right data but $id never fills in, not even if I put a string for the value in the form.
<table>
<form method="post" action="updateUser.php">
<tr>
<td></td><td align="right"><input type="text" id="id1" value="<?php echo "$id" ; ? >" ></input></td>
</tr>
<tr>
<td align="right">Enter your current password:</td><td align="right"><input type="text" id="user1"></td>
</tr>
</br>
<tr>
<td align="right">Enter your new username:</td><td align="right"><input type="text" id="user2"></td>
</tr>
<tr>
<td></td><td><input type="submit" value="Change"></input></td>
</form>
</tr>
And here is the relevant updateUser.php:
$id = $_GET['id1'];
$password = $_GET['user1'];
$newUser = $_GET['user2'];
$username = $_SESSION['username'];
Upvotes: 0
Views: 62
Reputation: 1168
There are a few issues with the form you have here.
Any input that you need to grab data from should have a name=
attribute.
Closing out a block of PHP code should look like ?>
Observe how <input>
elements close in the following code.
Some HTML structure issues: I believe the <form>
should wrap around the <table>
, and if you need space between table rows, it should be accomplished with styles, rather than a <br />
.
The following is the cleaned up code:
<form method="post" action="updateUser.php">
<table>
<tr>
<td></td>
<td align="right"><input type="text" id="id1" name="id1" value="<?php echo htmlentities("$id", ENT_QUOTES); ?>" /></td>
</tr>
<tr>
<td align="right">Enter your current password:</td>
<td align="right"><input type="text" id="user1" name="user1" /></td>
</tr>
<tr>
<td align="right">Enter your new username:</td>
<td align="right"><input type="text" id="user2" name="user2" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Change" /></td>
</tr>
</table>
</form>
Also note, the htmlentities()
call, in case your $id
has weird characters, or is not an integer. Probably not necessary, but just making sure.
With method='post', your code to grab those variables will be as follows:
$id = $_POST['id1'];
$password = $_POST['user1'];
$newUser = $_POST['user2'];
Upvotes: 2