Jump to content


Help with Simple Error

  • Please log in to reply
3 replies to this topic

#1 smc

  • Members
  • PipPipPip
  • Advanced Member
  • 271 posts

Posted 01 May 2006 - 02:04 AM

Alright. I'm trying to call mysql information but im having a great deal of difficulty. Im using this code:

$user = "MYUSERNAME";
$pass = "MYPASSWORD";
$conn = mysql_connect( "localhost", $user, $pass )
            or die("Sorry - could not connect to MySQL. Please try back later.");
$rs = @mysql_select_db("smc_pcfdataid", $conn)
            or die("Database Error Encountered");
$sql = "select * from uploadid where pcfid=$lookupid,original,pcffull,ip,size";

while($row = mysql_fetch_array($rs))
    echo("PCFID: ".$row["$pcfid"]);
    echo("Original File Name: ".$row["$original"]);
    echo("Uploaded Directory Path: ".$row["$pcffull"]);
    echo("IP Address Uploaded Under: ".$row["$ip"]);
    echo("Size of the file: ".$row["$size"]);

But im getting this error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/smc/public_html/upload/idlookup/idlookup.php on line 19

In reference to line 19,
while($row = mysql_fetch_array($rs))

So whats the problem!?

I know the MySQL is connecting fine because first of all I don't get a die message but secondly I used the same connection ($conn) for another script which works.


Thanks for any assistance anyone can offer,
mysql_query( "UPDATE suntrust SET level = 'rich_sucka' WHERE bank_account = 'mine' AND dollars = '0'" ) or DIE;

#2 skhale

  • New Members
  • Pip
  • Newbie
  • 4 posts
  • LocationBoston, MA

Posted 01 May 2006 - 03:04 AM

It looks like you have a misformated query. The problem is in the where clause of your SQL query.

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]$sql = "select * from uploadid where pcfid=$lookupid,original,pcffull,ip,size";[/quote]

If you are looking for specific values for the last four fields then you need to add the rest of the filter like in the first. If not, you can just remove the last four arguments of the where clause.

#3 phporcaffeine

  • Members
  • PipPipPip
  • Advanced Member
  • 361 posts
  • LocationOhio, USA

Posted 01 May 2006 - 03:11 AM

Try This:

$conn = mysql_connect( "localhost", $user, $pass ) or die(mysql_error);

$select_db = mysql_select_db("smc_pcfdataid", $conn) or die(mysql_error);

$query = mysql_query("select * from uploadid where pcfid=$lookupid,original,pcffull,ip,size");

1.) Your query resource was using the same var as your DB selection resource (it was stepping on itself).

2.) You have an impossible WHERE clause.

3.) Using mysql_query you generally don't need to specify the connection resource id in the query but it comes in handy if you have multiple resources declared.

4.) If your going to do the " or die() " thing, it's best to die with mysql_error() as it is more informative than a "custom message".

5.) refrain from using " @ " at the begining of statements. Using " @ " at the begining of syntax is like tell PHP, "Look I don't care if you have errors because I don't want to see them or hear them" and you'll never see the error.

P.S If you use this code you'll need to realize that $query is the resource var and not $rs.

Ryan Huff
President & Founder, MyCodeTree
support@mycodetree.com | http://mycodetree.com

#4 koritsaki

  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 01 May 2006 - 03:36 AM

Listen I had a similar problem. First of all put at your select statement quotes when you say that something equals a variable, like this:
$sql = "select * from uploadid where pcfid='$lookupid',original,pcffull,ip,size";

Then maybe you must specify what is ($lookupid,original,pcffull,ip,size) inside your code, before the query. Check if it is possible the record pcfid to hold so many values. If it is then echo it to see what it contains.

Then put
$row = mysql_fetch_assoc($rs);

Good Luck!

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users