Page 1 of 1

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

Posted: Thu May 15, 2008 11:35 am
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.

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

Posted: Thu May 15, 2008 11:45 am
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.

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

Posted: Thu May 15, 2008 11:46 am
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"'.

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

Posted: Thu May 15, 2008 12:23 pm
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