Forum Moderators: coopster

Message Too Old, No Replies

No error message but no data added?

php mysql problem

         

Awful newbie

9:52 pm on May 6, 2007 (gmt 0)

10+ Year Member



This is my script for uploading binary files and store them in mysql. It runs without error, but no file is added to the db? Anyone with a hint?

Here it goes:

<?php
// code that will be executed if the form has been submitted:

if ((isset($_POST['submit']))&&(isset($_FILES['form_data']))) {
upload();
} else {
show_form();
}//end if

function upload() {
//includes
// Connects to your Database
mysql_connect("localhost", "no_way", "you_get_it") or die(mysql_error());
mysql_select_db("database_2") or die(mysql_error());

//define variables
$image_file = '';
$image_desc = '';
$rabatt = '';
$type = '';
$size = 0;
$name = '';

$image_file = $_FILES['form_data']['tmp_name'];
$image_desc = $_POST['form_description'];
$rabatt = $_POST['rab_kat'];
$type = $_FILES['form_data']['type'];
$size = $_FILES['form_data']['size'];
$name = $_FILES['form_data']['name'];

$data = fread(fopen($image_file, "r"), filesize($image_file));
$data = addslashes($data);
$result=mysql_query("INSERT INTO the_table (description,rabatt,bin_data,filename,filesize,filetype) ".
"VALUES ('$image_desc','$rab_kat','$data','$name','$size','$type')");

$id= mysql_insert_id();
print "<p>This file has the following Database ID: <b>$id</b>";

//show the form again to load the next image
show_form();
}

function show_form()
{
// else show the form to submit new data:
?>

<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>" enctype="multipart/form-data">
File description:<br>
<input type="text" name="form_description" size="40">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000"><br />
File Category:<br>
<select name="rab_kat">
<option selected="selected">Choose:</option>
<option value="10">Option 1</option>
<option value="20">Option 2</option>
<option value="30">Option 3</option>
<option value="40">Option 4</option>
</select>
<br>File to upload/store in database:<br>
<input type="file" name="form_data" size="40">
<p>
<input type="submit" name="submit" value="submit">
<input type="button" name="move" value="Show" onClick="javascript:window.location='show_desc.php';">
</p>
</form>

<?php
}
?>
</body>

uh, the sql table is here:

id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY,
rabatt CHAR(5),
submitter CHAR(50), (not used)
sub_url CHAR(50), (not used)
dato DATETIME, (not used yet)
bin_data LONGBLOB,
filename CHAR(50),
filesize CHAR(50),
filetype CHAR(50)

phparion

5:30 am on May 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



first of all use [php.net...] to check if the file is uploaded..

second step could be to add a DIE() with mysql_query too

third step could be to print your query to see its actual shape and apply it directly on database