Image file doesn't appear in the db table

Can you give me some ideas why the image file is uploading to the /upload/ folder, but not into the db table named ‘videos’ column named ‘thumbnail’?

$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 ( filename ) VALUES( '$thumbnail' )";
mysql_query($sql);
$file_location = '<a href="http://www.....com/upload/' . $thumbnail . '">' . $thumbnail .      '</a>';

Any help will be appreciated, I’d be happy to provide addtional info or files/code

Probably the space around field name “filename” or is it “thumbnail”? Turn on error reporting during development. Use back ticks or no space around field names.

$sql = "INSERT INTO videos (thumbnail) VALUES( '$thumbnail' )";

Thank you for your reply. Can you please give me an example of what I need to “Turn on error reporting”? Also, when the code is this:

$sql = "INSERT INTO videos (thumbnail) VALUES( '$thumbnail' )";

The image file name appears in the thumbnail column, in the ‘videos’ table, but in its own row, not in the row with all the other Upload Form info.
Can you please help me teak this so it’s all in the same row?

// Report all PHP errors (see changelog)
error_reporting(E_ALL);

At the top of your PHP file.

Hard to know what you are talking about. You haven’t posted any form or “other” table processing code. If this “Image processing” is supposed to go in another table with other POST processing, make it so.

Thanks for your replies. After adding error_reporting(E_ALL); and processing the Form, I see no errors.

Also, I’m not looking to have the image to “go in another table” I’m trying to get the image file to go into the same ‘videos’ table like the rest of the Upload Form entries do.

Here is the Form code:

<form enctype="multipart/form-data" action="uploader.php" method="POST">
<div id="upload-video"><br /><br />
<ul>
<li style="width:240px; text-align:right;"><strong>[var.lang_title]:</strong></li>
<li style="width:400px; text-align:left;"><input name="title" type="text" class="upload- video-form-input" value="[var.title]" size="38" />
</li>

<li style="width:240px; text-align:right;"><strong>[var.lang_description]:</strong><br />        </li>
<li style="width:400px; text-align:left;"><textarea rows="4" name="description"  id="description" cols="29" class="upload-video-form-input">[var.description]</textarea><br  />

</li>
<li style="width:240px; text-align:right;"><strong>Search Words:</strong></li>
<li style="width:400px; text-align:left;"><input name="tags" type="text" class="upload- video-form-input" value="[var.tags]" size="38" />
</li>
<li style="width:240px; text-align:right;"><strong>Image:</strong></li>
<li style="width:240px; text-align:right;"><input type="file" name="file" id="file"    class="upload-video-form-input2"></li>

<li style="width:240px; text-align:left; margin-top:60px;"><strong></strong></li>
<li style="width:400px; text-align:left;">
<!--<select class="upload-video-form-input" style="width:160px;" size="1"  name="channel" onchange="javascript:ahahscript.ahah('[var.base_url]/uploader.php? sub_cat='+ document.form_upload.channel.value, 'sub_change', '', 'GET', '', this);">-->
<input type="hidden" name="channel" value="5"/>
</li>
<table id="tabZ13">
<tbody>
<tr>
<li style="width:240px; text-align:right;"><strong></strong></li>
<li style="width:400px; text-align:left;">
<input type="hidden" name="public_private" value="public"></li>
<input class="button-form" type="submit" value="Next &gt;&gt;" name="B3" />
</li>
</td></tr>
</tbody>
</table>
</ul>
<input class="upload-video-form-input" type="hidden" name="form_submitted"  value="yes" />
</form>

Any additional help will be appreciated.

Do a var_dump() on $sql, are you sending to the database what you think you’re sending?

btw, are you aware that the old mysql_* extension is deprecated?

Can you please give me an example of how to “Do a var_dump() on $sql”?

http://php.net/manual/en/function.var-dump.php

var_dump($sql);

Thanks for the replies/help.
After adding

var_dump($sql);

and running the Form to upload the Image file “test.png”, I see this:

string(53) “INSERT INTO videos (thumbnail) VALUES( ‘test.png’ )”

I’m not sure what to do with that info. Any additional help is welcomed.

Well it seems to me you would want to validate the other form inputs and trim/escape these values before entering them with the same INPUT script that adds the thumbnail name.

Thanks for your reply/insight. I’m sure that’s probably a good idea, but I’m not sure if that will get me to my primary goal of getting the image file into the same row as the other Form entry info, because what you’re suggesting is beyond my knowledge of how to do that, or why to do that, and it seems that the other form inputs are already appearing successfully. So, any additional help with getting the image file into the same row, will be greatly appreciated.

I usually make sure display is on too when debugging.

/* development debugging */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
//error_reporting(0);
//ini_set('display_errors', FALSE);
1 Like

Thanks for your repy>
After adding:
/* development debugging */
error_reporting(E_ALL);
ini_set(‘display_errors’, TRUE);
//error_reporting(0);
//ini_set(‘display_errors’, FALSE);

but I don’t see anything.

Well then if you are already adding the other data with another INSERT query, then grab the record id and instead of making another INSERT query, UPDATE the record to add the thumbnail name.

Thank you for your reply. much appreciated.

In the ‘videos’ table the first column is ‘indexer’, no record id, that I can see there.
Would it be somewhere else?

Could you please give me an example an sql statement that might work with UPDATE, ‘videos’ and thumbnail, (and indexer) please?

Any help will be greatly appreciated.

IS ‘indexer’ a primary auto increment field?
You say you are adding the other info. If you add this directly after that query it should give you the ID number of that record.

$IDnum = mysql_insert_id();

You then should be able to use an UPDATE query to add the thumnail.

$sql = "UPDATE videos SET thumbnail = '$thumbnail' WHERE indexer = '$IDnum'";

Thanks so much for your effort/reply. Much appreciated.
Yes, ‘indexer’ is a primary auto_increment field.
I added:

$IDnum = mysql_insert_id();
$sql = "UPDATE videos SET thumbnail = '$thumbnail' WHERE indexer = '$IDnum'";

ran the Form, but the image file didn’t appear in the table

Any additional thought will be appreciated.

…Must be immediately after your first INSERT query.
Did you echo the update sql to see if all values are in place?

thanks so much for your reply.
However, just to be clear, where is my “fiest INSERT query” here:

$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 ( filename ) VALUES( '$thumbnail' )";
mysql_query($sql);
$file_location = '<a href="http://www.....com/upload/' . $thumbnail . '">' . $thumbnail .          '</a>';

I thought I was supposed to replace:

$sql = "INSERT INTO videos ( filename ) VALUES( '$thumbnail' )";

wth this:

$sql = "UPDATE videos SET thumbnail = '$thumbnail' WHERE indexer = '$IDnum'";