473,499 Members | 1,609 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

value taking from db (mysql)

20 New Member
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

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head></head>
  3. <body>
  4. <form enctype="multipart/form-data" action="#" method="POST">
  5. <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
  6. Choose a file to upload: <input name="uploadedfile" type="file" /><br />
  7. <input type="submit" value="Upload File" />
  8. </form>
  9. </body>
  10. </html>
  11. <?php
  12. //include("dbinfo.inc.php");
  13. function db_connect()
  14. {
  15. $dbHost = "localhost";
  16. $dbUser = "root";
  17. $dbDatabase = "ajeesh";
  18. $db = mysql_connect("$dbHost", "$dbUser", "") or die ("Error connecting to database.");
  19. mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database.");
  20. }
  21.  
  22. echo db_connect();
  23. $target_path = "uploads/";
  24.  
  25. $name=$_FILES['uploadedfile']['name'];
  26. $size=$_FILES['uploadedfile']['size'];
  27. $type=$_FILES['uploadedfile']['type'];
  28. $path="uploads/".$name;
  29. echo "-------------".$name;
  30. echo "<br />-----------".$tmpname;
  31. $size=$size/1024;
  32. echo "<br />-------------".$size."kb"."<p></p>";
  33. echo "-------------------".$type;
  34. $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
  35.  
  36. if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) 
  37. {
  38.     echo "The file ".( $_FILES['uploadedfile']['name']). " has been uploaded";
  39.     $sql="INSERT INTO upload "."(name,size,path) "."VALUES "."('$name','$size','$tmpname')";
  40.     $result=mysql_query($sql);
  41.     //echo $result;
  42.     //downloading-----------------------------------------------------------------------------------------------------------
  43.     $sqlc="select path from upoad where name='arrow.png'";
  44.     $result=mysql_query($sqlc);
  45.  
  46.      while ($line = mysql_fetch_array($result)) {
  47.  
  48.     foreach ($line as $col_value) {
  49.         echo "$col_value";
  50.     }
  51. }
  52.     echo "********************************************************";
  53.     echo $path;
  54. }
  55.  else
  56. {
  57.     echo "There was an error uploading the file, please try again!";
  58. }
  59.  
  60. mysql_close(db_conect());
  61.  
  62. ?>
Oct 5 '09 #1
8 1769
ajeeshc
20 New Member
how to take a value from the database and shown to the client
Oct 5 '09 #2
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:
Expand|Select|Wrap|Line Numbers
  1. 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:
Expand|Select|Wrap|Line Numbers
  1. $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.
Oct 5 '09 #3
TheServant
1,168 Recognized Expert Top Contributor
Expand|Select|Wrap|Line Numbers
  1. $raw_result = mysql_query("SELECT value FROM table WHERE something='$something'");
  2. $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?
Oct 5 '09 #4
ajeeshc
20 New Member
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
Oct 5 '09 #5
ajeeshc
20 New Member
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 ........


Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head></head>
  3. <body>
  4. <form enctype="multipart/form-data" action="#" method="POST">
  5. <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
  6. Choose a file to upload: <input name="uploadedfile" type="file" /><br />
  7. <input type="submit" value="Upload File" />
  8. </form>
  9. </body>
  10. </html>
  11. <?php
  12. //include("dbinfo.inc.php");
  13.  
  14.  
  15. $dbHost = "localhost";
  16. $dbUser = "root";
  17. $dbDatabase = "ajeesh";
  18. $db = mysql_connect("$dbHost", "$dbUser", "") or die ("Error connecting to database.");
  19. mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database.");
  20.  
  21.  
  22. $target_path = "uploads/";
  23.  
  24. $name=$_FILES['uploadedfile']['name'];
  25. $size=$_FILES['uploadedfile']['size'];
  26. $type=$_FILES['uploadedfile']['type'];
  27. $path="uploads/".$name;
  28. echo "-------------".$name;
  29. //echo "<br />-----------".$tmpname;
  30. $size=$size/1024;
  31. echo "<br />-------------".$size."kb"."<p></p>";
  32. echo "-------------------".$type."<p></p>";
  33. $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
  34.  
  35. if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) 
  36. {
  37.  
  38.     echo "The file ".( $_FILES['uploadedfile']['name']). " has been uploaded"."<p></p>";
  39.     $sql="INSERT INTO upload "."(name,size,path) "."VALUES "."('$name','$size','$tmpname')";
  40.     $result=mysql_query($sql);
  41.     //echo $result;
  42.     //downloading-----------------------------------------------------------------------------------------------------------
  43.     $sqlc="select path from upload where name='arrow.png'";
  44.     $resultc=mysql_query($sqlc);
  45.     //$line=mysql_fetch_array($resultc);
  46.  
  47.      while ( $line=mysql_fetch_array($resultc))
  48.       {
  49.  
  50.           echo "wwwwwwwwwwwwwwwwwwwwwww";
  51.         echo "Name :{$line['name']} <br>" ;
  52.             }
  53.  
  54.     echo "-------------".$path;
  55. }
  56.  
  57.  else
  58. {
  59.     echo "There was an error uploading the file, please try again!";
  60. }
  61.  
  62. mysql_close($db);
  63.  
  64. ?>
Oct 5 '09 #6
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.
Oct 5 '09 #7
TheServant
1,168 Recognized Expert Top Contributor
I'm confused, were these topics merged? I am sure they were two different ones before??
Oct 5 '09 #8
Atli
5,058 Recognized Expert Expert
@TheServant
Yes, this topic was posted in three different threads, which I merged into this one thread.
Oct 6 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
8858
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...
3
2758
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...
0
1201
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...
11
4827
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...
1
5459
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...
6
5882
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...
2
2048
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...
0
997
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...
33
3254
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...
0
7014
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...
0
7180
Oralloy
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,...
0
7395
tracyyun
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...
0
5485
agi2029
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,...
1
4921
isladogs
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...
0
3108
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...
0
3103
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
311
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.