Image is deleted when table is updated

J

Jim

Guest
First allow me say "Thank You" for a wonderful and powerful utility in DaDaBIK. It has saved me time over and over again.

I have recently decided to add some images to one of my databases. Upon first adding an image it appears when displaying a record. The problem is when I update any of the fields of the table and save the changes. The image no longer appears. The filename is deleted from the field in the table.

I have read all the Forums and could not find an answer to my question so I am hoping someone has experienced this and found a solution.

I am using the latest version.

All help is appreciated.

Jim
 
L

lbr

Guest
I have encountered the same problem .

I have several "generic_file" fields in my database , when I add a first document : no problem , it appears when displaying a record .
But when I add another file or update any fields , all the previous recordings are erased .

lbr
 
J

Jim

Guest
I'm glad it wasn't just me. I was beginning to think I was missing something. It happens in any field that I set to upload a file to.

I hope someone can offer a solution soon as this particular bug has me stopped cold in my tracks on my current project.

Jim
 
G

grz

Guest
same problem,

i think there's a bug in the php script which post empty
value when the upload file form is empty. there's no check.

the problem is that empty value is recorded in the mysql table and
erase any previous.

the solution is to re-enter all the value each time but it's really not a
solution at all.

regards,
 
G

grz

Guest
i've made some modifications to the business_logic.php script near line 1246 and added a simple condition. The file/image doesn't disappear anymore when updating another field.

here's how it looks now :
<...>

$name_field_temp = $fields_labels_ar[$i]["name_field"];
$file_name = $HTTP_POST_FILES["$name_field_temp"]['name'];

if($file_name != "") {
$sql .= "".$quote."".$fields_labels_ar[$i]["name_field"]."".$quote." = ";
$sql .= "'".$file_name."', ";

}

break;

<...>
And it works as it should !!

if anyone is interested, i could send the full business_logic.php...

Good night.
 
J

Jim

Guest
qrz,

Yes, please email it to me so that I won't make a mistake editing my file. My email address is:

tvi@bellsouth.net

Thanks,
Jim
 
G

grz

Guest
hummm,

----- Transcript of session follows -----
... while talking to mx07.mail.bellsouth.net.:
>>> DATA
<<< 550 .net 003: you are not allowed to send e-mail to <tvi@bellsouth.net>
550 5.1.1 <tvi@bellsouth.net>... User unknown
<<< 503 No recipients specified

a mistake ? :)
 
G

grz

Guest
for those who are interested, the file could be found here :

http://grz.free.fr/business_logic.php.txt

regards,

Elie.


ps : it's not perfect as you cannot revert an upload field to an empty value.
most important is that it works.
 
M

Mark

Guest
Be careful here. Vesion 2.2.1 won't accept grz's correction as is. The correct code (which is simply a modification of grz's) looks like this (around line 1239 of business_logic.php). This places "// add the field name to the sql statement" within each case statement.

switch ($fields_labels_ar[$i]["type_field"]){
case "generic_file":
case "image_file":
$name_field_temp = $fields_labels_ar[$i]["name_field"];
$file_name = $HTTP_POST_FILES["$name_field_temp"]['name'];
if($file_name != "") {
$sql .= "".$quote."".$fields_labels_ar[$i]["name_field"]."".$quote." = "; // add the field name to the sql statement
$sql .= "'".$file_name."', "; // add the field value to the sql statement
}
break;
case "select_multiple_menu":
case "select_multiple_checkbox":
$sql .= "".$quote."".$fields_labels_ar[$i]["name_field"]."".$quote." = "; // add the field name to the sql statement
$sql .= "'";
for ($j=0; $j<count($$fields_labels_ar[$i]["name_field"]); $j++){
$sql .= $fields_labels_ar[$i]["separator_field"].${$fields_labels_ar[$i]["name_field"]}[$j];// add the field value to the sql statement
} // end for
$sql .= $fields_labels_ar[$i]["separator_field"]; // add the last separator
$sql .= "', ";
break;
case "update_date":
$sql .= "".$quote."".$fields_labels_ar[$i]["name_field"]."".$quote." = "; // add the field name to the sql statement
$sql .= "'".date("Y-m-d H:i:s")."', "; // add the field name to the sql statement
break;
case "date":
$sql .= "".$quote."".$fields_labels_ar[$i]["name_field"]."".$quote." = "; // add the field name to the sql statement
$field_name_temp = $fields_labels_ar[$i]["name_field"];
$year_field = $field_name_temp."_year";
$month_field = $field_name_temp."_month";
$day_field = $field_name_temp."_day";
$mysql_date_value = $$year_field."-".$$month_field."-".$$day_field;
$sql .= "'".$mysql_date_value."', "; // add the field value to the sql statement
break;
default: // textual field and select single
$sql .= "".$quote."".$fields_labels_ar[$i]["name_field"]."".$quote." = "; // add the field name to the sql statement
$sql .= "'".$$fields_labels_ar[$i]["name_field"]."', "; // add the field value to the sql statement
break;
} // end switch
 
M

mkrz

Guest
The solution posted by Mark only works if you delete line 1237:

$sql .= "".$quote."".$fields_labels_ar[$i]["name_field"]."".$quote." = ";

where the field name gets inserted into the sql statement. With Mark's solution you only insert the field name if the field is not empty. Hope this helps.
 
R

Rob

Guest
Has anyone solved this problem yet? I'm still trying it (2.2.1) - with general files, not with image files - and with grz's script, I get a query error, or it just updates the DB with 1s and 0s where the file should go.

:(

Rob
 
M

Mark

Guest
Not sure if this helps, it's somewhat a reiteration of my earlier suggestion.

Be sure to arrange your logic to ensure both the:

$sql .= "".$quote."".$fields_labels_ar[$i]["name_field"]."".$quote." = "; // add the field name to the sql statement

and:

$sql .= "'".$file_name."', "; // add the field value to the sql statement

are executed together. This is the sql statement that the program feeds mySQL UPDATE. (syntax

UPDATE [LOW_PRIORITY] [IGNORE] tbl_name
SET col_name1=expr1 [, col_name2=expr2, ...]
[WHERE where_definition]
[ORDER BY ...]
[LIMIT #]

The first line sets $sql to "col_name1" and the second line sets $sql to "expr1". if you don't set both of these, you'll get an mySQL error.

The original fix that grz offers doesn't work with version 2.2.1 because of what I described above.

Hope this helps
 
R

Rob

Guest
Here's what's showing up in my mysql.log file when I try to update with the code you put...

69 Query update `2003` set 'Rob', 'Test', 'Demo', '', '', '', '', '', '', '', '', '', '', '', '', '', 'Yes' where professor_id =
'36'

It looks like the colname stuff isn't coming through.

Hmm.

Rob
 
J

jim

Guest
Can someone please email the new businesslogic.php for the new release
I have messed this up 3 times so far :)
 
P

PLMresearch

Guest
I'd be happy to send the biz logic, unfortunately, I've really customized the heck out of it, so it wouldn't be of any help. What version are you running? If it's Vesion 2.2.1, look at my earlier comments (and the subsequent contributions).

Be sure to arrange your code (around line 1239 of business_logic.php). so both the:

$sql .= "".$quote."".$fields_labels_ar[$i]["name_field"]."".$quote." = "; // add the field name to the sql statement

and:

$sql .= "'".$file_name."', "; // add the field value to the sql statement

are executed together.

This is the sql statement that the program feeds mySQL UPDATE. (syntax

UPDATE [LOW_PRIORITY] [IGNORE] tbl_name
SET col_name1=expr1 [, col_name2=expr2, ...]
[WHERE where_definition]
[ORDER BY ...]
[LIMIT #]

The original Vesion 2.2.1 code separated the two in the case statement (and therefore the sql update never occured).
 
E

Eugenio

Guest
Hi all,
I've fixed the bug and I think I will release the new version of DaDaBIK in the next few days; this version also add some features to the upload feature.

Bye,

Eugenio.

(Latest version of DaDaBIK when this message was posted: 2.2.1 beta)
 
Top