Newbie question: calling a variable

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
FeRdI
Forum Newbie
Posts: 2
Joined: Sun Aug 24, 2003 12:36 pm

Newbie question: calling a variable

Post by FeRdI »

Hi all. I've just started learning php. I've installed everything succesfully using php 4.3.2 on WinXP pro.

Though there's a problem that keeps bugging me. The following code doesn't work:

Code: Select all

while ($row = mysql_fetch_array($numrows)) 
    { 
        echo "Before action: ".$row[ja];
        $ja = $row[ja];
    }

    $voted = $_POST[voted]; #<- tried it with and without this function

    if ($voted == 1)
        {
            $ja++;
            $add = mysql_query ("UPDATE telenamen SET ja = $ja WHERE id = 00001");
            echo "<BR> After Action: ".$ja;
            if (!add) { echo "Failure"; }
        }
Then I execute the php with *.php?voted=1
It doesn't do anything this way, but when I put it like this it works:

Code: Select all

while ($row = mysql_fetch_array($numrows)) 
    { 
        echo "Before action: ".$row[ja];
        $ja = $row[ja];
    }

$voted = $_POST[voted];
$voted = 1; # <- I've add this one...

    if ($voted == 1)
        {
            $ja++;
            $add = mysql_query ("UPDATE telenamen SET ja = $ja WHERE id = 00001");
            echo "<BR> After Action: ".$ja;
            if (!add) { echo "Failure"; }
        }
Does anybody know what I'm doing wrong here or what makes this script fail?

Thank you very much in advance,

Ferdi
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

First, $_POST[voted] should be $_POST['voted'],. and secondly, where is the voted variable coming from. Would need to see that as well.
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

Then I execute the php with *.php?voted=1
Sorry, didn't see that line

Change $_POST to $_GET

$_POST is submitted in the body of the request, $_GET is submitted in the header, or the URL
User avatar
delorian
Forum Contributor
Posts: 223
Joined: Sun May 04, 2003 5:20 pm
Location: Olsztyn, Poland

Post by delorian »

As I can see from your post, I can tell you only that, you should start reading the manual on http://php.net first, or some nice tutorial. You can also read the stickies from PHP - Normal section on this forum. Of course, I can tell you where's and what's making that problem, (oh and I see that Jason already done that... :) But please read the manual. It's the best thing to do while learning PHP.
FeRdI
Forum Newbie
Posts: 2
Joined: Sun Aug 24, 2003 12:36 pm

Post by FeRdI »

Oh great guys,
Thanks for your help!

Man that's stupid of me
Post Reply