Solved

$_GET and $_POST Problems

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

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

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

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…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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 look for a specific file type in a local or remote server directory using PHP.

630 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