Sorry, this thread has the wrong title. It should be "Image file doesn't appear in the correct row". Anyway, can you give me some ideas why the image file is uploading to the /upload/ folder, and into the thumbnail column (of the table named 'videos') but only into its own row, instead of into the same row as the rest of the Upload Form entries? $allowedExts = array("gif", "jpeg", "jpg", "pdf", "png"); $temp = explode(".", $_FILES["file"]["name"]); $extension = strtolower( end($temp) ); if (!in_array($extension,$allowedExts)) { echo ("Error - Invalid File Name"); } $length = 20; $thumbnail = $_SESSION['user_id'].$_FILES["file"]["name"]; move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $thumbnail); $sql = "INSERT INTO videos ( thumbnail ) VALUES( '$thumbnail' )"; mysql_query($sql); $file_location = '<a href="http://www.....com/upload/' . $thumbnail . '">' . $thumbnail . '</a>'; Code (markup): Any help will be appreciated, I'd be happy to provide addtional info or files/code
Because you're not telling it which row it's supposed to upload to? You need to use a WHERE-clause to tell the info where it needs to go.
Thanks for your reply. I don't know how to tell it where to go. I don't know how to identify the row. Any help with that will be greatly appreciated.
From the text in your first post it looks like the file is being uploaded and is to be linked to existing information in your site - for example a profile picture or a product image. In your sql statement you have $sql = "INSERT INTO videos ( thumbnail ) VALUES( '$thumbnail' )"; PHP: This creates a new row in the database and doesn't have any info in it to link it to anything else in your database. I'd expect, at the very least, the IP of the person uploading the image, but more likely the person's ID, the datetime of upload, a title and description.
Thanks for your reply. Yes, the 'videos' table has 'indexer' (which is a new record_id number for each row) and video_id, both of which I believe get created upon 'submit'. I thought something like: $sql = "UPDATE videos SET thumbnail='$thumbnail' WHERE video_id = '????'"; Code (markup): might work, but I need additional help, with that or any other ideas, please.
Well, that means you now have two entries with "INSERT INTO" in the processing of the form - turn it into one, after the upload has taken place? The code you posted is just a snippet, and therefore it's hard to tell you exactly what to do - if you're using a proper database handler, for instance PDO, you could also do a $query->lastInsertId() after the first insert, to get the ID of the row, and then use that value in the second insert, but again, why don't you just combine the two?
Which really should be the first fix here, as someone should already have read you the riot act about using the deprecated soon to no longer be supported mysql_ functions that we've been told for EIGHT YEARS to stop using, and that they finally two and a half years ago added giant red warning boxes to the manual waving you off. Though really we're not seeing your database structure -- is there an auto-update field or some other tracking value for that insert? You also shouldn't be relying on explode to parse your URI's... there can be issues with that and its' why PHP has the pathinfo function. Don't be brute forcing things PHP already has functions to handle.
Thanks for all of the replies. Can I please get an example of "you could also do a $query->lastInsertId() after the first insert, to get the ID of the row, and then use that value in the second insert, but again, why don't you just combine the two?" Also, no I don't believe there is an "auto-update field"
Can you please post the complete code for that function / call, so we can see how the first bit is being inserted also? Basically, you just combine the two insert-queries you have now into one - place it where the insert-query you posted above is, and that should basically do it - unless you're going in and out of functions or loops in the code. And you should look into using something else than mysql_ as @deathshadow said - it's deprecated, and really, REALLY not recommended