Solved

$_GET and $_POST Problems

Posted on 2004-10-19
6
222 Views
Last Modified: 2006-11-17
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
Comment
Question by:drunkdrinks
6 Comments
 
LVL 12

Accepted Solution

by:
minichicken earned 43 total points
ID: 12355689
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
 
LVL 49

Expert Comment

by:Roonaan
ID: 12355833
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
 
LVL 3

Assisted Solution

by:Boris Aranovich
Boris Aranovich earned 41 total points
ID: 12356311
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
 
LVL 1

Assisted Solution

by:rweston
rweston earned 41 total points
ID: 12475043
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question