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
https://forums.phpfreaks.com/topic/82335-solved-why-is-no-one-helping-me/
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? :)

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.