Help needed with the image update on form.

Okay, there were 2 error’s unexpected “}” and undefined “Resize_function” i deleted said } and defined Resize.

It refreshes fine to profile but doesn’t add or change the image?

OK,

Lets comment out the redirect[php]//header(“Location: view01.php?id=” . $id);[/php]
Does it show you the db query it is attempting?

No?

commenting out the redirect goes to a blank white page in the browser.

nothing else.

the url has no id.

www.removalspace.com/view02.php

OK,

I think I was misunderstanding when you said it wasn’t updating the image.

Did you mean the file, or the database table entry?

If you meant in the table, the problem is that you do not have a query to update the file.

Right now you code looks for a change in the website, phone, phone2 premiumuser_description, username, and/or password. It should make the appropriate changes to any of those columns if they have included in the form’s post.

To get the image name to be included in the query, we will need to add some code. Lets try the following:[php]include (‘php only scripts/db.php’);

if(isset($_REQUEST[‘id’])) $id = $_REQUEST[‘id’]; // guarantee it’s a harmless number value
else
{
echo ‘You cannot access this page directly…’;
exit;
}

if (isset($_POST[‘website’]) && !empty($_POST[‘website’])) { // does the GET value exists and has it a value ?
$website = mysql_real_escape_string($_POST[‘website’]); // get its value and escape it
$setArray[] = “website = ‘$website’”; // ok to update this field in the query so store it
}
if (isset($_POST[‘phone’]) && !empty($_POST[‘phone’])) {
$phone = mysql_real_escape_string($_POST[‘phone’]);
$setArray[] = “phone = ‘$phone’”;
}
if (isset($_POST[‘phone2’]) && !empty($_POST[‘phone2’])) {
$phone2 = mysql_real_escape_string($_POST[‘phone2’]);
$setArray[] = “phone2 = ‘$phone2’”;
}
if (isset($_POST[‘premiumuser_description’]) && !empty($_POST[‘premiumuser_description’])) {
$premiumuser_description = mysql_real_escape_string($_POST[‘premiumuser_description’]);
$setArray[] = “premiumuser_description = ‘$premiumuser_description’”;
}
if (isset($_POST[‘username’]) && !empty($_POST[‘username’])) {
$username = mysql_real_escape_string($_POST[‘username’]);
$setArray[] = “username = ‘$username’”;
}
if (isset($_POST[‘password’]) && !empty($_POST[‘password’])) { // These are the same so you’d need to make them different if your comparing the password to ensure they entered it correctly ex: $_GET[‘password1’] for another field in your form
$password= mysql_real_escape_string($_POST[‘password’]); // This is fine if the 2 values above are first compared
$setArray[] = “password = SHA(’$password’)”; // If they are compared and validation checks out then just do the query to update the password here…
}
if (isset($_POST[‘upload’]) && !empty($_POST[‘upload’])) {
$upload = mysql_real_escape_string($_POST[‘upload’]);
$setArray[] = “upload = ‘$upload’”;
}
/* check if form was submitted /
if (isset($_POST[‘submit’])){
$error_message = “”;
/
This is the directory where images will be saved /
$target = “/home/users/web/b109/ipg.removalspacecom/images/COMPANIES/”;
if(!is_dir($target)) echo “1. Directory Doesn’t Exist: $target
”;
$target = $target . basename( $_FILES[‘upload’][‘name’]);
/
include validation script /
// include (‘php only scripts/validation.php’);
$uploadDir = ‘/home/users/web/b109/ipg.removalspacecom/images/COMPANIES’; /
main picture folder /
$max_height = 450; /
largest height you allowed; 0 means any /
$max_width = 450; /
largest width you allowed; 0 means any /
$max_file = 2000000; /
set the max file size in bytes /
$image_overwrite = 1; /
0 means overwite; 1 means new name /
/
add or delete allowed image types /
$allowed_type01 = array(“image/gif”, “image/pjpeg”, “image/jpeg”, “image/png”, “image/x-png”, “image/jpg”);
$do_thumb = 1; /
1 make thumbnails; 0 means do NOT make /
$thumbDir = “/home/users/web/b109/ipg.removalspacecom/images/thumbs”; /
thumbnail folder /
if(!is_dir($thumbDir)) echo “2. Directory Doesn’t Exist: $thumbDir
”;
$thumb_prefix = “”; /
prefix for thumbnails /
$thumb_width = 90; /
max thumb width /
$thumb_height = 70; // max thumb height
//Writes the photo to the server
if(move_uploaded_file($_FILES[‘upload’][‘tmp_name’], $target)) {
/
HERE IS WHERE WE WILL DO THE ACTUAL RESIZING /
/
THESE SIX PARAMETERS MAY BE CHANGED TO SUIT YOUR NEEDS /
$upload = $_FILES[‘upload’][‘name’];
$o_path =“images/COMPANIES/”;
if(!is_dir($o_path)) echo “3. Directory Doesn’t Exist: $o_path
”;
$s_path = “images/thumbs/”;
if(!is_dir($s_path)) echo “4. Directory Doesn’t Exist: $s_path
”;
$file = $upload;
$save = $file;
$t_w = 200;
$t_h = 150;
/
DO NOT CHANGE THIS NEXT LINE */

  Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path);
  $setArray[] = "upload = '$file'";

}
}else{
//Gives and error if its not
$error_message .= “Sorry, there was a problem uploading your file.”;
}

if (count($setArray) > 0) { // do we have at least on field to update?
$setstr = join (’, ', $setArray); // form a comma separated string of our updates
$query = “UPDATE companies SET $setstr WHERE id = $id”; // update it
echo $query;
mysql_query($query) or die(mysql_error());
}

header(“Location: view01.php?id=” . $id);[/php]

I remembered to remove the extra bracket !!! ;D

That works perfectly!! Cannot thank you enough. A whole month of being stuck/confused and worn out.

What do i owe ya? 8)

:o …it…it…it…it…works?

;D I’m thrilled its working for you! Please feel free to let me know if you run into any other issues.

Best,

jay

Thanks again Jay! :smiley:

Andy

Sponsor our Newsletter | Privacy Policy | Terms of Service