Solved

$_GET and $_POST Problems

Posted on 2004-10-19
6
216 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

706 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now