Solved

$_GET and $_POST Problems

Posted on 2004-10-19
6
227 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

738 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