Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 234
  • Last Modified:

$_GET and $_POST Problems

I have a php file (http://www.drunkdrinks.com/drink.txt) that is giving me a couple problems.  The actualy php doc can be seen at http://www.drunkdrinks.com/drink.php?drinkid=289.  On the bottom are two forms for emailing the drink to a friend and rating the drink.  They don't work yet, I am close to having them both work.  I think the $_GET and $_POST variables are out of whack - do you see what the problem is?
0
drunkdrinks
Asked:
drunkdrinks
3 Solutions
 
minichickenCommented:
Check for missing ; (semi colons)

like some of them are missing....

<?php printf($_GET['drinkid']) ?>

Don't think that should be the problem, but it worth a try, to insert the ;

good luck...
0
 
RoonaanCommented:
Minichicken is right, I just would like te make a side comment on the html you are using.

It is poorly written, as you don't even use quotes arround your attributes and lots of times using uppercase tagnames.This is quite oldfashioned!

Regards

-r-
0
 
Boris AranovichCommented:
Several things:

First of all, about security.
It is extremely easy to hack in to the database when you're passing unverified user-input to the query... You should verify the input and escape it.

Secondly, about loops.
Instead of doing

   if ($myrow = mysql_fetch_array($result)) {
     do {
        ....
      } while ($myrow = mysql_fetch_array($result));
   }

you could easily replace it with

while ($myrow = mysql_fetch_array($result)) {
    ...
}

Next, about the $_GET[] and $_POST[], what is the problem with them exactly?
I see you are submitting a 'post' form with the 'drinkid' field, but in the SQL trying to use $_GET['drinkid']... try $_POST['drinkid'] instead...

Now this loop again:
   if ($myrow = mysql_fetch_array($result)) {
        do {
         $pagetitle = $myrow["title"];
         $directions = $myrow["directions"];
         $hits = $myrow["hits"];
         $drinkrating = $myrow["rating"];
         $userid = $myrow["userid"];
         $category = $myrow["category"];
      } while ($myrow = mysql_fetch_array($result));
   }

You are aware that you are fetching many rows, and overwriting the same variables each time, so eventually you have only the last row...?
0
 
rwestonCommented:
like people have suggested, see what the GET & POST vars contain or if for some reason you're not sure which method is being used, try REQUEST;

<?

echo("<pre>");  #  For formatting;
print_r($_GET);
print_r($_POST);
print_r($_REQUEST);
echo("</pre>");

?>

Throw that into the page data is being posted to.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now