Page 1 of 1

hidden variable not working correctly

Posted: Sat Oct 25, 2008 5:51 pm
by steve_linn
new programmer-
I cannot get a variable to pass between these php pages?

/index.php?content=showaccount&id=97055512120001

I want the id to pass to the next page

page is called 'enteraccount2.inc.php'

Code: Select all

 
<form action=index.php method=post target="_self">
<input type="hidden" name="custid" value="<? echo $_GET['id']; ?>"> 
 
<h2>Enter account information here!!</h2><br>
 
<table width="300" border="0">
  <tr>
  </tr>
  <tr>
    <td>email </td>
    <td><input type="text" name="email"></td>
  </tr>
  <tr>
    <td>password</td>
    <td><input type="text" name="password"></td>
  </tr>
  <tr>
 <td><input type="submit" value="Submit">
 
<input type="hidden" name="content" value="updateaccount"></td>
</form>
 
I want the id to pass to the next page
updateaccount.inc.php

Code: Select all

 
<?php
 
$custid = $_GET['id'];
$email = $_GET['email'];
$password = $_GET['password'];
 
{
$query = "INSERT INTO account (custid, email, password)" . 
" VALUES ('$custid', '$email', '$password')";
$result = mysql_query($query);
if ($result) 
echo "<h2>Updates posted to account</h2>\n";
else
echo "<h2>Sorry, there was a problem posting your updates</h2>\n";
echo "<a href=\"index.php?content=showaccount&id=$custid\">Return to show account</a>\n";
}
 
?>
 
I keep getting the message "there was a problem posting your updates "

where did I go wrong?

Re: hidden variable not working correctly

Posted: Sat Oct 25, 2008 6:09 pm
by requinix

Code: Select all

<input type="hidden" name="[color=blue]custid[/color]" value="<? echo $_GET['id']; ?>">

Code: Select all

$custid = $_GET['[color=blue]id[/color]'];
One or the other, not both.

And I suggest using

Code: Select all

<?php echo intval($_GET['id']); ?>
instead of what you have now.

Re: hidden variable not working correctly

Posted: Sat Oct 25, 2008 6:29 pm
by steve_linn
I'm not following you...

on the enteraccount2.inc file I should change to the code you recommend?

what about changes to the updateaccount.inc page?

Re: hidden variable not working correctly

Posted: Sat Oct 25, 2008 6:33 pm
by requinix

Code: Select all

<input type="hidden" name="[color=blue]custid[/color]" value="<? echo $_GET['id']; ?>">

Code: Select all

$custid = $_GET['[color=blue]id[/color]'];
In the HTML form you call it "custid" but in your PHP code you look for "id". You can only use one.
Also your form uses POST but your code uses GET. Again, you can only use one.

Re: hidden variable not working correctly

Posted: Sun Oct 26, 2008 12:03 am
by steve_linn
my sincerest thanks!