Can't Set value for image

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sirstrumalot
Forum Commoner
Posts: 27
Joined: Mon May 18, 2009 10:26 pm

Can't Set value for image

Post 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.
Last edited by Benjamin on Mon May 18, 2009 10:54 pm, edited 1 time in total.
Reason: Changed code type from text to php.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Can't Set value for image

Post 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.
sirstrumalot
Forum Commoner
Posts: 27
Joined: Mon May 18, 2009 10:26 pm

Re: Can't Set value for image

Post 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?
sirstrumalot
Forum Commoner
Posts: 27
Joined: Mon May 18, 2009 10:26 pm

Re: Can't Set value for image

Post 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.
Post Reply