Page 1 of 1

Can't Set value for image

Posted: Mon May 18, 2009 10:36 pm
by sirstrumalot
I have the following code:

Code: Select all

//Calls the last entry into the database
mysql_select_db($database_contacts, $missed_visits);
$query_missed = "SELECT * FROM missedVisit ORDER BY missed_id DESC limit 1";
$missed = mysql_query($query_missed, $missed_visits) or die(mysql_error());
$row_missed = mysql_fetch_assoc($missed);
$totalRows_missed = mysql_num_rows($missed);
 
//names and uploads the file
//  $time = time()+1;
$filename = "\.\.\/\.\.\/images\/employees\/missedvisit\/".$row_missed['missed_id']."\_employee\.jpg";
imagejpeg($img, "$filename", 100);
imagedestroy($img);
$rootimg = "\.\.\/images\/employees\/missedvisit\/".$row_missed['missed_id']."\_employee\.jpg";
$id = $row_missed['missed_id'];
 
$updateSQL = "UPDATE missedVisit SET missed_image=".$rootimg." WHERE missed_id=".$id."";
$rsl = mysql_query($updateSQL);
 
    set_msg('Record Added');
    $cid = $row_missed['missed_id'];
    $redirect = "../../missedvisit-details.php?id=$cid";
    header('Location: '.$redirect); die;
The signature capture flash application is directed here where it creates the temp image, resizes it, gives it a file name and stores it into the database in the MissedVisit table under an existing record which is called to be updated by the Primary Key 'missed_id'. The value of the file's location is stored in 'missed_image' Then redirects to the details page where the record is shown as updated.

My problem is when I create the image and come through this file, it will create the jpg, store it as the correct file name with the correct location, but will not update the database. I suspect it is the concatenation or escape keys. What would be the proper syntax for this? The value is NULL each time. No Errors.

Re: Can't Set value for image

Posted: Mon May 18, 2009 11:06 pm
by requinix

Code: Select all

$updateSQL = "UPDATE missedVisit SET missed_image=".$rootimg." WHERE missed_id=".$id."";
echo out that query and see if it looks correct to you.

Re: Can't Set value for image

Posted: Mon May 18, 2009 11:28 pm
by sirstrumalot
Okay, so I took the escape characters out. They were put in my one of my guys trying to give it a whirl. Here is the result I got and it's corresponding updated code:

Code: Select all

UPDATE missedVisit SET missed_image= ../images/employees/missedvisit/31_employee.jpg WHERE missed_id=31
Corresponding Code:

Code: Select all

//Calls the last entry into the database
mysql_select_db($database_contacts, $missed_visits);
$query_missed = "SELECT * FROM missedVisit ORDER BY missed_id DESC limit 1";
$missed = mysql_query($query_missed, $missed_visits) or die(mysql_error());
$row_missed = mysql_fetch_assoc($missed);
$totalRows_missed = mysql_num_rows($missed);
 
//names and uploads the file
//  $time = time()+1;
$filename = "../../images/employees/missedvisit/".$row_missed['missed_id']."_employee.jpg";
imagejpeg($img, "$filename", 100);
imagedestroy($img);
$rootimg = "../images/employees/missedvisit/".$row_missed['missed_id']."_employee.jpg";
$id = $row_missed['missed_id'];
 
$updateSQL = "UPDATE missedVisit SET missed_image= ".$rootimg." WHERE missed_id=".$id."";
$rsl = mysql_query($updateSQL);
 
    set_msg('Record Added');
    $cid = $row_missed['missed_id'];
    $redirect = "../../missedvisit-details.php?id=$cid";
    header('Location: '.$redirect); die;
 
 
The value for the field is still NULL. It's not updating the 'missed_image' column with the appropriate data. Any ideas?

Re: Can't Set value for image

Posted: Mon May 18, 2009 11:37 pm
by sirstrumalot
Got it. Here's the fix:

Code: Select all

$updateSQL = "UPDATE missedVisit SET missed_image='".$rootimg."' WHERE missed_id='".$id."'";
I needed to add the apostrophes to the quotations to allow the format to be queried as such

Code: Select all

UPDATE missedVisit SET missed_image="../value/value.jpg" WHERE missed_id='##';

Thanks for the hint.