473,473 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

UPDATE Query and File Blobs

38 New Member
HI there,

I had a similar problem yesterday with my delete function. All looks ok, yet doesn't delete. I've tried adding the '$_GET' to the sql query, without any success. Is this perhaps a problem with the file uploads? The row ID is definately being posted correctly.

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?
  3. include("connect.php"); 
  4.  
  5. if(isset($_POST['Submit']) && $_POST['Submit'] == "Submit")
  6. {
  7.     $fileName = $_FILES['userfile']['name'];
  8.     $tmpName  = $_FILES['userfile']['tmp_name'];
  9.     $fileSize = $_FILES['userfile']['size'];
  10.     $fileType = $_FILES['userfile']['type'];
  11.  
  12.     $fp      = fopen($tmpName, 'r');
  13.     $content = fread($fp, filesize($tmpName));
  14.     $content = addslashes($content);
  15.     fclose($fp);
  16.  
  17.     if(!get_magic_quotes_gpc())
  18. {
  19.     $fileName = addslashes($fileName);
  20. }
  21.  
  22.  
  23.     $resourceName = $_FILES['resource']['name'];
  24.     $tmpName  = $_FILES['resource']['tmp_name'];
  25.     $resourceSize = $_FILES['resource']['size'];
  26.     $resourceType = $_FILES['resource']['type'];
  27.  
  28.     $fp      = fopen($tmpName, 'r');
  29.     $resourceContent = fread($fp, filesize($tmpName));
  30.     $resourceContent = addslashes($resourceContent);
  31.     fclose($fp);
  32.  
  33.     if(!get_magic_quotes_gpc())
  34. {
  35.     $resourceName = addslashes($resourceName);
  36. }
  37.  
  38.    $tutorialNumber = $_POST['tutorialNumber'];
  39.    $tutorialTitle = $_POST['tutorialTitle'];
  40. $tutorialDescription = $_POST['tutorialDescription'];
  41. $tutorialContent = $_POST['tutorialContent'];
  42.  
  43.  
  44. mysql_query("UPDATE tutorials SET tutorialTitle='$tutorialTitle', tutorialDescription='$tutorialDescription', tutorialContent='$tutorialContent', name='$fileName', size=$filesize, type='$filetype, content='$content', resourceName='$resourceName', resourceSize=$resourceSize, resourceType='$resourceType, resourceContent='$resourceContent' WHERE  tutorialNumber = '$tutorialNumber'");
  45.  
  46.  
  47.  echo "<span class='titles'>Edit Complete!</span><br><br>";
  48. }
  49. // ************* End update part *************
  50.  
  51.  
  52. $tutorialNumber=$_GET['tutorialNumber'];
  53.  
  54. $result=mysql_query("select * from tutorials where tutorialNumber='$tutorialNumber'");
  55. or die ('Error querying database.');
  56. $row=mysql_fetch_assoc($result);
  57.  
  58. mysql_close();
  59. ?>
  60.  
  61.  
Many thanks
Aug 15 '09 #1
9 2631
Philth
38 New Member
Just out of interest, if the file upload field is left blank in this UPDATE form, will it over write the file that was originally posted in the database?

If so, is there a reasonably simple way around this?
Aug 15 '09 #2
Philth
38 New Member
Anybody got any ideas?
Aug 16 '09 #3
code green
1,726 Recognized Expert Top Contributor
Anybody got any ideas?
I have really no idea what your problem is.
All looks ok, yet doesn't delete
I cannot see a DELETE query
I've tried adding the '$_GET' to the sql query
Please explain how you use $_GET in SQL
Is this perhaps a problem with the file uploads?
Could be. But without any error trapping or debugging in your code it is impossible to know what is happening.
You need about half a dozen more 'if' statements in your code
Aug 17 '09 #4
Philth
38 New Member
Thanks for the reply,

Sorry I meant UPDATE, not DELETE.

You'll have to forgive me, I'm a complete novice. I've used $_GET in the following way before...

Expand|Select|Wrap|Line Numbers
  1.  
  2. $query = ("DELETE FROM tutorials WHERE tutorialNumber = '".$_GET["id"]."' LIMIT 1");
  3.  
  4.  
I just thought I might be able to use a similar query with the problem above. Evidently not.
Aug 17 '09 #5
code green
1,726 Recognized Expert Top Contributor
You should avoid the habit of using data straight from a form into a query.
Read about "SQL Injection".
Although it works so that is not the problem.

I suspect a problem with the file hence my suggestion for more testing.
By that I mean at least
Expand|Select|Wrap|Line Numbers
  1. if($fp = fopen($tmpName, 'r')){
  2.     if($content = fread($fp, filesize($tmpName))){
  3.         echo $content;
  4.        $content = addslashes($content); 
  5.         if(!fclose($fp))
  6.          echo 'Could not close file';
  7.     }
  8.     else echo 'Could not read file';
  9. }
  10. else 'Could not open file';
  11.  
This won't 'make it work' but it will help debug
Aug 17 '09 #6
Philth
38 New Member
I've basically boiled it down to this. I've stripped out any mention of images uploads etc and still it doesn't work.

What am I doing wrong with the "or die" command? Not even that is working.

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?
  3.  
  4. include("connect.php"); 
  5. if(isset($_POST['Submit']) && $_POST['Submit'] == "Submit")
  6. {
  7. $courseID=$_POST['courseID'];
  8. $courseTitle = $_POST['courseTitle'];
  9.  
  10. $str = "UPDATE course SET courseTitle='{$courseTitle}' WHERE courseID='{$courseID}'";
  11. mysql_query($str) or die("Query failed:<br>".mysql_error());
  12. echo "<span class='titles'>Edit Complete!</span><br><br>";
  13. }
  14. ?>
  15.  
  16. <?
  17. include("connect.php"); 
  18. $courseID=$_GET['courseID'];
  19. $result=mysql_query("select * from course where courseID='$courseID'");
  20. $row=mysql_fetch_assoc($result);
  21. ?>
  22.  
  23.  
  24.    <form action="process_edit_course.php" method="post" enctype="multipart/form-data">
  25. <input type="hidden" name="courseID" value="<?php echo $row['courseID']; ?>">
  26.     <TABLE width="100%" cellpadding="0" cellspacing="10" bgcolor="#FFFFFF" class="border">
  27.       <br>
  28.       <TR valign="top"> 
  29.         <TD width="388"><span class="bodytext">Course Title: </span></TD>
  30.       </TR>
  31.       <TR valign="top">
  32.         <TD width="388"><input name='courseTitle' type='text' class="border" id="courseTitle" value="<? echo $row['courseTitle']; ?>" size="45" /></TD>
  33.       </TR>
  34.       <TR valign="top">
  35.         <TD><input type="submit" name="submit" value="Add Course to Libary" /></TD>
  36.       </TR>
  37.     </TABLE>
  38. </form>
  39.  
  40.  
Aug 17 '09 #7
code green
1,726 Recognized Expert Top Contributor
Rather than the 'or die' command I prefer to handle the error cleanly and continue.
However, you must remember that 'or die' will only action if your function returns false, which is basically an error.
So if the query executes without an error but does nothing then you will not know, because your code still lacks if statements.

Expand|Select|Wrap|Line Numbers
  1. print_r($_POST);
  2. if(isset($_POST['Submit']) && $_POST['Submit'] == "Submit") 
  3. $courseID=$_POST['courseID'];
  4. if(!isset($_POST['courseID']))
  5.   echo 'No courseID';
  6. echo $courseID;
  7. $courseTitle = $_POST['courseTitle']; 
  8. echo $courseTitle ;
  9.  
  10. $str = "UPDATE course SET courseTitle='{$courseTitle}' WHERE courseID='{$courseID}'"; 
  11. echo $str;
  12. $res = mysql_query($str) or die("Query failed:<br>".mysql_error());
  13. echo $res 
  14. echo "<span class='titles'>Edit Complete!</span><br><br>"; 
  15. else echo 'Form not submitted';
  16.  
Basically you are not helping by working blind;
Aug 18 '09 #8
Philth
38 New Member
Thankss for your help - I appreciate the tips.
Aug 18 '09 #9
code green
1,726 Recognized Expert Top Contributor
No problem. Once you can see what is happening it is much easier to pinpoint the fault.
If you can't then post back.

EDIT: By the way, I forgot to include make use of
Expand|Select|Wrap|Line Numbers
  1. mysql_num_rows()
  2. mysql_rows_affected()
Aug 19 '09 #10

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

Similar topics

3
by: David Stockwell | last post by:
Hi, I'd like to read the contents of a file into memory. The problem is that this file is binary. I then want to store the whole thing in memory to a database as a blob. I have no problem...
0
by: Justin Case | last post by:
I have a Perl app that stores pictures in a blob. Now I want to load a thumbnail version of the picture into another blob column, but the update fails with a syntax error. I'm able to insert the...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
7
by: Howard Lowndes | last post by:
My situation is that I am interacting PHP 4.1.2 to PostgreSQL 7.2.2 I have no difficulty inserting and managing BLOBs into the Large Object system table, and I have a user table called images...
4
by: John Baker | last post by:
Hi: I have two tables, a setup table (TblSetup) and a purchase order table (tblPO). When i construct a query with ONLY the tblPO shown, and a type in parameter for the PO number, I an update...
5
by: Louis LeBlanc | last post by:
Hey folks. I'm new to the list, and not quite what you'd call a DB Guru, so please be patient with me. I'm afraid the lead up here is a bit verbose . . . I am working on an application that...
2
by: Jerry LeVan | last post by:
Hi, I am just getting into large objects and bytea "stuff". I created a small db called pictures and loaded some large objects and then tried to do a restore. Here is how I got the dump. ...
4
by: Ian Davies | last post by:
Hello I have seen some tutorials to put a update a counter field in a record. I have the counter field in a table that also has a field for a path to file. I display the records in a table on...
1
by: tofu.captain | last post by:
I have PDFs saved in a SQL 2005 server as BLOBs. I would like to extract the BLOBs and either: 1. create a PDF file on the hard disk or 2. open/stream the PDF into the application I am...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
1
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
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.