hidden variable not working correctly

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
steve_linn
Forum Newbie
Posts: 20
Joined: Thu Jul 10, 2008 1:10 pm

hidden variable not working correctly

Post 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?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: hidden variable not working correctly

Post 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.
steve_linn
Forum Newbie
Posts: 20
Joined: Thu Jul 10, 2008 1:10 pm

Re: hidden variable not working correctly

Post 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?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: hidden variable not working correctly

Post 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.
steve_linn
Forum Newbie
Posts: 20
Joined: Thu Jul 10, 2008 1:10 pm

Re: hidden variable not working correctly

Post by steve_linn »

my sincerest thanks!
Post Reply