0

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']; 
5
  • 2
    form method="post" != $_GET[...]; ... you need to use $_POST Commented Jul 15, 2013 at 18:22
  • 2
    also your inputs dont have name attributes Commented Jul 15, 2013 at 18:23
  • 1
    You have a closing PHP tag which looks like ? > in the <input> element and though I've not tested, I suspect PHP won't attempt to honor that. ?> it should look like. Commented Jul 15, 2013 at 18:23
  • ... Yes, indeed it's a parse error: codepad.viper-7.com/JTQgLJ which means you should enable error reporting: error_reporting(E_ALL); ini_set('display_errors', 1); Commented Jul 15, 2013 at 18:24
  • @Michael Berkowski, It just copied wierd it doesn't look like that in my code, I tried with $_POST and didn't get any difference, i'm adding 'name' attributes next... Commented Jul 15, 2013 at 18:37

1 Answer 1

2

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']; 
Sign up to request clarification or add additional context in comments.

1 Comment

it needed the name attribute and the $_POST, looks like I need to read up on forms and PHP :) thanks guys.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.