I've created 2 php files but getting mysql_fetch_array() err

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
egturnkey
Forum Commoner
Posts: 34
Joined: Sun Jul 26, 2009 7:35 pm

I've created 2 php files but getting mysql_fetch_array() err

Post by egturnkey »

Hello Friends ,

I've made a simple 2 php files but when i do run it, it gives error as following

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\eshtrak\z.php on line 7

( i think there an error in WHERE catID='".$_GET['catID']."' AND productID=".$_GET['productID'] )

Here is the php code

Code: Select all

 
<?php
include_once('config.php'); // connect 2 DB
 
$productSQL = "SELECT * FROM product WHERE catID='".$_GET['catID']."' AND productID=".$_GET['productID'];
$productresult = mysql_query($productSQL);
$productrow = mysql_fetch_array($productresult);
 
 
echo "{$productrow['name']}";
 
?>
 
and if you need to review the database table is as following

Code: Select all

 
CREATE TABLE `product` (
  `productID` int(11) NOT NULL auto_increment,
  `catID` int(11) NOT NULL,
  `name` varchar(255) NOT NULL default '',
  `demo` varchar(255) NOT NULL default '',
  `description` text NOT NULL,
  `keywords` text NOT NULL,
  `compatibilities` text NOT NULL,
  `downloadURL` varchar(255) NOT NULL default '',
  `status` int(1) NOT NULL default '0',
  `type` int(1) NOT NULL default '0',
  `price` float(10,2) NOT NULL,
  `userID` int(11) NOT NULL default '0',
  `creation_date` bigint(14) NOT NULL,
  PRIMARY KEY  (`productID`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=20 ;
 

also if you want to review the config.php

Code: Select all

 
<?
$dbuser = "root";
$dbhost = "localhost";
$dbpass = "art";
$dbname = "my";
@mysql_connect($dbhost,$dbuser,$dbpass);
@mysql_select_db($dbname);
?>
 
User avatar
Salaria
Forum Commoner
Posts: 34
Joined: Fri Feb 13, 2009 2:50 am
Location: India
Contact:

Re: I've created 2 php files but getting mysql_fetch_array() err

Post by Salaria »

Hi,

I checked your code and It's working fine for me. Please make sure that you are GETting values to properly.

Try debugging and apply echo statement as follows:

echo "SELECT * FROM product WHERE catID='".$_GET['catID']."' AND productID=".$_GET['productID'];

and write Query in same context as

$productSQL = "SELECT * FROM product WHERE catID='".$_GET['catID']."' AND productID='".$_GET['productID']"'";

Hope this will help.
Post Reply