Jump to content

[SOLVED] why is no one helping me????


chishake

Recommended Posts

i have another problem again. i am trying to check if an image i want to upload into my database already exist. i have used the

$result= SELECT  name from images WHERE name = $name,

($name = $_FILES['userfile']['name'])

$result = mysql_query($result);

$num=mysql_numrows($result);

if($num >0)

{

echo " there is a file in the database with name $name, upload a different file";

exit();

}

this piece of code gives me this error

 

Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource

it works on other pieces of data but not on my image table.

can anyone tell me why and how i can go about to sort this out since i want to make sure i am not uploading a file already in the database

Link to comment
Share on other sites

I dont really understand the ($name={FILES....  part as ive never come across it before, but i'd write it just like this..

 

($name = $_FILES['userfile']['name'])
$result=@mysql_query("SELECT name from images WHERE name = $name"); 

$num=@mysql_num_rows($result); 
if($num >0)
{
echo " there is a file in the database with name $name, upload a different file";
exit();
}

 

or maybe follow the way you did it and do :

 

$result=@mysql_query("SELECT name from images WHERE name = $name, ($name = $_FILES['userfile']['name'])"); 

$num=@mysql_num_rows($result); 
if($num >0)
{
echo " there is a file in the database with name $name, upload a different file";
exit();
}

 

Hope that works? :)

Link to comment
Share on other sites

you will also get the error if there is an error with your sql statement. Use Sensei's suggestions below to help debug your sql statement.

 

You may want to start using some Quotes

 

<?php
$name = $_FILES['userfile']['name'];
$sql = "SELECT `name` from `images` WHERE name = '$name'";
$result = mysql_query($sql) or die(mysql_error());
$num=mysql_num_rows($result);
if($num >0)
{
echo " there is a file in the database with name $name, upload a different file";
exit();
}
?>

 

Ray

Link to comment
Share on other sites

the problem get worst after adding the die(mysql_error())

this is what i get

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'JPG' at line 1

 

JPG is the type of file i am trying to upload

Link to comment
Share on other sites

this code has solved the problem.

<?php

$name = $_FILES['userfile']['name'];

$sql = "SELECT `name` from `images` WHERE name = '$name'";

$result = mysql_query($sql) or die(mysql_error());

$num=mysql_num_rows($result);

if($num >0)

{

echo " there is a file in the database with name $name, upload a different file";

exit();

}

?>

 

thanks you folks

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.