Jump to content

Help with Simple Error


smc

Recommended Posts

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

[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";
$rs=mysql_query($sql,$conn);

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"]);
    echo("http://www.smc.xeeblo.net/uploaded/".$row["$pcffull"]);
}
[/code]

But im getting this error:
[code]
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
[/code]

In reference to line 19,
[code]
while($row = mysql_fetch_array($rs))
[/code]

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.

Help!

Thanks for any assistance anyone can offer,
SMC
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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:
[code=php:0]
$sql = "select * from uploadid where pcfid='$lookupid',original,pcffull,ip,size";
[/code]

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
[code=php:0]
$rs=mysql_query($sql,$conn);
$row = mysql_fetch_assoc($rs);
[/code]

Good Luck!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.