Uutiset:

Wondering if this will always be free?  See why free is better.

Main Menu
Advertisement:

Problems with querystring-passing PHP/MySQL

Aloittaja rozilla, elokuu 07, 2007, 12:00:11 AP

« edellinen - seuraava »

rozilla

i did all the tutorials in Parham's in EasyPHP. everything worked fine. so, i adapted the script below from a tutorial on webmonkey.com [nofollow]. worked fine offline in EasyPHP, too.

but once i upload it to test it online, it doesn't work. the querystring gets passed, but instead of outputting the stuff specified in the if($category) block, i keep getting the output from the else-block. what gives??

script in action: http://businessdirectory.clickafricana.com/categories.php [nofollow]

<?php

dbh
=mysql_connect ("localhost""<USERNAME>""<PASSWORD>") or die ('I cannot connect to the database because: ' mysql_error());
mysql_select_db ("<DB-NAME>");*/

// display individual record
if ($category)
{
   
$result mysql_query("SELECT * FROM <code>businesses</code> WHERE <code>category</code> = '{$category}' ORDER by bizname;"$dbh);
   
$myrow mysql_fetch_array($result);
   echo 
"<h2>Category: $category</h2>";
   do
   {
      
printf("<p><b>%s</b>\n<br />"$myrow["bizname"]);
      
printf("%s\n<br />"$myrow["description"]);
      
printf("%s\n<br />"$myrow["address"]);
      
printf("%s\n<br />"$myrow["country"]);
      
printf("%s\n<br />"$myrow["telephone"]);
      if (
$myrow["url"])
        
printf("<a href=\"$myrow[7]\" target=\"_blank\">%s</a>\n<br />"$myrow["url"]);
      if (
$myrow["email"])
        
printf("<a href=\"mailto:$myrow[8]\">%s</a>\n</p><br />"$myrow["email"]);
      echo
"<hr>";
    }while(
$myrow mysql_fetch_array($result));
}
else
{
// show categories list
   
$result mysql_query("SELECT * FROM categories ORDER BY category",$dbh);

    if (
$myrow mysql_fetch_array($result))
    {
// display list if there are records to display
      
do
      {
        
printf("<a href=\"%s?category=%s\">%s</a><br>\n"$PHP_SELF$myrow["category"], $myrow["category"]);
      } while (
$myrow mysql_fetch_array($result));
    }
    else
    {
// no records to display
      
echo "Sorry, no records were found!";
    }
}

?>

Advertisement: