i want to display the path of file in browser that i am uploaded to the server
for later downloading but when iam trying to do this using the mysql_fetch_array()
it not working
an error like
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\xampp\session1\upload.php on line 47
here the code i used - <html>
-
<head></head>
-
<body>
-
<form enctype="multipart/form-data" action="#" method="POST">
-
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
-
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
-
<input type="submit" value="Upload File" />
-
</form>
-
</body>
-
</html>
-
<?php
-
//include("dbinfo.inc.php");
-
function db_connect()
-
{
-
$dbHost = "localhost";
-
$dbUser = "root";
-
$dbDatabase = "ajeesh";
-
$db = mysql_connect("$dbHost", "$dbUser", "") or die ("Error connecting to database.");
-
mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database.");
-
}
-
-
echo db_connect();
-
$target_path = "uploads/";
-
-
$name=$_FILES['uploadedfile']['name'];
-
$size=$_FILES['uploadedfile']['size'];
-
$type=$_FILES['uploadedfile']['type'];
-
$path="uploads/".$name;
-
echo "-------------".$name;
-
echo "<br />-----------".$tmpname;
-
$size=$size/1024;
-
echo "<br />-------------".$size."kb"."<p></p>";
-
echo "-------------------".$type;
-
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
-
-
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
-
{
-
echo "The file ".( $_FILES['uploadedfile']['name']). " has been uploaded";
-
$sql="INSERT INTO upload "."(name,size,path) "."VALUES "."('$name','$size','$tmpname')";
-
$result=mysql_query($sql);
-
//echo $result;
-
//downloading-----------------------------------------------------------------------------------------------------------
-
$sqlc="select path from upoad where name='arrow.png'";
-
$result=mysql_query($sqlc);
-
-
while ($line = mysql_fetch_array($result)) {
-
-
foreach ($line as $col_value) {
-
echo "$col_value";
-
}
-
}
-
echo "********************************************************";
-
echo $path;
-
}
-
else
-
{
-
echo "There was an error uploading the file, please try again!";
-
}
-
-
mysql_close(db_conect());
-
-
?>
8 1769
how to take a value from the database and shown to the client
TheServant 1,168
Recognized Expert Top Contributor @ajeeshc
First of all, please use [code] tags around your code so we can read it.
You will notice that you are looking in the table "upoad" rather than "upload" so I am guessing that is the major problem.
Consider using mysql syntax by puting the commands in capitals to improve readability like: - SELECT path FROM upload WHERE name='arrow.png'
It may seem silly for such a simple statement, but it's a practice which makes your code a lot easier to read for you and anyone else!
How you can search for this in the future is when developing, you can include something like: - $result=mysql_query($sqlc) or die('There has been an error: '.mysql_error());
Which will tell you (for example): table "upoad" could not be found.
Let us know if you still have problems and I will have a more thorough look.
TheServant 1,168
Recognized Expert Top Contributor - $raw_result = mysql_query("SELECT value FROM table WHERE something='$something'");
-
$result = mysql_fetch_array($raw_result)
Have a look in Google
I am pretty sure you know this from your other post, so could you be more specific what you don't know?
i tried
but error showing
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\xampp\session1\upload.php on line 47
i am very new to php i try to display the file that uploaded to the db in this the while loop is not working i cant figure it out any one please help ........ - <html>
-
<head></head>
-
<body>
-
<form enctype="multipart/form-data" action="#" method="POST">
-
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
-
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
-
<input type="submit" value="Upload File" />
-
</form>
-
</body>
-
</html>
-
<?php
-
//include("dbinfo.inc.php");
-
-
-
$dbHost = "localhost";
-
$dbUser = "root";
-
$dbDatabase = "ajeesh";
-
$db = mysql_connect("$dbHost", "$dbUser", "") or die ("Error connecting to database.");
-
mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database.");
-
-
-
$target_path = "uploads/";
-
-
$name=$_FILES['uploadedfile']['name'];
-
$size=$_FILES['uploadedfile']['size'];
-
$type=$_FILES['uploadedfile']['type'];
-
$path="uploads/".$name;
-
echo "-------------".$name;
-
//echo "<br />-----------".$tmpname;
-
$size=$size/1024;
-
echo "<br />-------------".$size."kb"."<p></p>";
-
echo "-------------------".$type."<p></p>";
-
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
-
-
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
-
{
-
-
echo "The file ".( $_FILES['uploadedfile']['name']). " has been uploaded"."<p></p>";
-
$sql="INSERT INTO upload "."(name,size,path) "."VALUES "."('$name','$size','$tmpname')";
-
$result=mysql_query($sql);
-
//echo $result;
-
//downloading-----------------------------------------------------------------------------------------------------------
-
$sqlc="select path from upload where name='arrow.png'";
-
$resultc=mysql_query($sqlc);
-
//$line=mysql_fetch_array($resultc);
-
-
while ( $line=mysql_fetch_array($resultc))
-
{
-
-
echo "wwwwwwwwwwwwwwwwwwwwwww";
-
echo "Name :{$line['name']} <br>" ;
-
}
-
-
echo "-------------".$path;
-
}
-
-
else
-
{
-
echo "There was an error uploading the file, please try again!";
-
}
-
-
mysql_close($db);
-
-
?>
Markus 6,050
Recognized Expert Expert @ajeeshc
Please see reply #3. You have an error in your MySQL query that is preventing mysql_query() from returning a valid resource to be used in mysql_fetch_array() (as the error quite clearly explains). So, if you apply the technique suggested by TheServant, that is, the section on using 'or die(mysql_erro());', you'll be informed of the error in your query.
Mark.
TheServant 1,168
Recognized Expert Top Contributor
I'm confused, were these topics merged? I am sure they were two different ones before??
Atli 5,058
Recognized Expert Expert @TheServant
Yes, this topic was posted in three different threads, which I merged into this one thread.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: tornado |
last post by:
Hi all,
I am pretty new to PHP. I was reading PHP manual and trying out the
example from 2nd
chapter (A simple Tutorial). When i try to print the variable as
given in the example it returns...
|
by: TekWiz |
last post by:
I've got a system that automatically generates a form. I have it set
up so that the backend will return to the inital form page with an
error object in sessions data (assuming the backend detected...
|
by: Tim Fountain |
last post by:
This may be a silly question but what can be done to stop
load-intensive MySQL processes taking down a server? Things like
adding fulltext indexes to very large tables, or selects on very large...
|
by: Randell D. |
last post by:
Folks,
I have a table of addresses and a seperate table with contact names -
All addresses tie to one or more names - I would like to keep track of
the number of names 'belonging' to an address...
|
by: suslikovich |
last post by:
Hi all,
I am getting this error when insert values from one table to another in
the first table the values are varchar (10). In the second they are
datetime. The format of the data is mm/dd/yyyy...
| |
by: Aston Martin |
last post by:
Hi All,
********************** My Situation **********************
I am working on project that involves passing a structure to unmanaged
code from .Net world (well using C#). Perhaps an example...
|
by: Brave |
last post by:
I'm hoping someone can help me with a small issue.
I have an asp page that displays informaton from an Access database.
I want to create a form that allows users to display only data that...
|
by: Extremest |
last post by:
Is there a way with php/mysql to have a set timeout period for
queries. My hosting provider is complaining about to many processes
when my pages connect to my db. Sometimes they take a few...
|
by: bill |
last post by:
In an application I am writing the user can define a series of
steps to be followed. I save them in a sql database using the
field "order" (a smallint) as the primary key.
(there are in the range...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |