Transferring a variable is giving me quite a headache...

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
nightswore
Forum Newbie
Posts: 13
Joined: Thu May 15, 2008 11:26 am

Transferring a variable is giving me quite a headache...

Post by nightswore »

So I am trying to get a button to, when clicked, add a specified amount to a value in a table. Since the buttons are created in a while loop, they have no unique identifiers, which is where my problem comes in. I want the button to only affect the row of the table that it is in, so in order to do this I set it up so that when it is clicked it will send the value I want affected to a separate php page where I will modify it, update the mysql database, and refresh the original page.

The problem I am having is that the variable that I want to send is already a php variable, and I'm trying to send it like this:

Code: Select all

   <form action="counter.php" method = post>
        <input name="used" type="hidden" value="<?php $info['used'] ?> ">
    <input type="submit" value="Used +1" >
 
And that would work fine for any other variable except one that needs to be in php tags. Either I get a blank result, (right now my 2nd php page just gets the post data and prints it out to make sure i'm getting what I want), or it works but, like I said, only with out the php tags.

So, does anyone know of a way for me to send that variable with the HTML input command with my php tags? Am I doing something completely bonkers? I've googled this stuff all morning and most of yesterday afternoon. If anyone has any ideas I'd really appreciate the help.

If there is anything confusing here, I will do my best to fix it asap, but I'm pretty sure I've explained myself thoroughly.
Dutchben
Forum Newbie
Posts: 12
Joined: Wed May 14, 2008 10:19 am

Re: Transferring a variable is giving me quite a headache...

Post by Dutchben »

First, in the examle you are giving you are not printing anything as a value

# <form action="counter.php" method = post>
# <input name="used" type="hidden" value="<?php $info['used'] ?> ">
# <input type="submit" value="Used +1" >

Should be

# <form action="counter.php" method = post>
# <input name="used" type="hidden" value="<?php print $info['used'] ?> ">
# <input type="submit" value="Used +1" >

I'm not sure if that's a typo in your example but i think this solves this quote.
And that would work fine for any other variable except one that needs to be in php tags. Either I get a blank result, (right now my 2nd php page just gets the post data and prints it out to make sure i'm getting what I want), or it works but, like I said, only with out the php tags.
Let me know if i misunderstood.
User avatar
Chalks
Forum Contributor
Posts: 447
Joined: Thu Jul 12, 2007 7:55 am
Location: Indiana

Re: Transferring a variable is giving me quite a headache...

Post by Chalks »

Code: Select all

   <form action="counter.php" method = post>
        <input name="used" type="hidden" value="<?php $info['used'] ?> ">
    <input type="submit" value="Used +1" >
 
The only thing I can see in the snippet you posted is that there is an extra space after '?>' that you probably shouldn't have there. Could you post the code from counter.php?


edit: Dutchbin is right... I didn't see that. Also, I would probably change 'method = post' to 'method="post"'.
nightswore
Forum Newbie
Posts: 13
Joined: Thu May 15, 2008 11:26 am

Re: Transferring a variable is giving me quite a headache...

Post by nightswore »

Wow...huh. I didn't even realize that I needed it to be printing 8O . Thanks a lot guys! It works perfectly now. Uh just throwing this in because you requested it:

Code: Select all

<?php
$newname = $HTTP_POST_VARS['used'];
echo $newname;
?>
But like I said, that was just to make sure I was getting the right value.

Now I can finish this darned project haha. :D
Post Reply