Jump to content

Recommended Posts

Hi everyone!

 

I am trying to add an update picture or logo to be precise, i used the same resize and crop technique from the register script but this dropped a NEW listing into my mySQL table, i would like to get that script to use it with the update system.

 

Here's the resize and crop script on register:

 

<?php /* check if form was submitted */
if (isset($_POST['Submit'])){
$error_message = "";
/* This is the directory where images will be saved */
$target = "server path"; 
$target = $target . basename( $_FILES['upload']['name']); 
/* include validation script */
include ('php only scripts/validation.php');
$uploadDir = '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 = "/images/thumbs";  /*  thumbnail folder */
$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/";
	$s_path = "images/thumbs/";
	$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);
}else{ 
	//Gives and error if its not 
	$error_message .= "Sorry, there was a problem uploading your file."; 
} ?>

 

here is the form, (just the upload bit, there are other fields):

 

<form action="view02.php" method="get" enctype="multipart/form-data" class="cursive">
<input name="upload" type="file" class="style7" id="upload">
<input type="submit" name="submit" value="submit" />
</form>

 

and the code to process form:

 

<?PHP
session_start();

include ('php only scripts/db.php');

$setArray = array();
$setstr = '';

$id = intval($_GET['id']);

if (isset($_GET['website']) && $_GET['website']) {
    $website = mysql_real_escape_string($_GET['website']);
    $setArray[] = "website = '$website'";
}
if (isset($_GET['phone']) && $_GET['phone']) {
    $phone = mysql_real_escape_string($_GET['phone']);
    $setArray[] = "phone = '$phone'";
}
if (isset($_GET['phone2']) && $_GET['phone2']) {
    $phone2 = mysql_real_escape_string($_GET['phone2']);
    $setArray[] = "phone2 = '$phone2'";
}
if (isset($_GET['premiumuser_description']) && $_GET['premiumuser_description']) {
    $premiumuser_description = mysql_real_escape_string($_GET['premiumuser_description']);
    $setArray[] = "premiumuser_description = '$premiumuser_description'";
}
if (isset($_GET['username']) && $_GET['username']) {
    $username = mysql_real_escape_string($_GET['username']);
    $setArray[] = "username = '$username'";
}
if (isset($_GET['password']) && $_GET['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($_GET['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($_GET['upload']) && $_GET['upload']) {
    $upload = mysql_real_escape_string($_GET['upload']);
    $setArray[] = "upload = '$upload'";
}

if (count($setArray) > 0) {
    $setstr = join (', ', $setArray);
    $query ="INSERT INTO `companies` 
(company_name, what_services, website, contact_name, location, postcode, street1, street2, city, phone,phone2, email, premiumuser_description, username, password, salt, approved, upload) 
VALUES ('$company_name', '$what_services', '$website', '$contact_name', '$location', '$postcode', '$street1', '$street2', '$city', '$phone', '$phone2', '$email', '$premiumuser_description', '$username', 'SHA($password)', '$salt', '$approved', '$upload')";
    mysql_query($query); 
}
header("Location: view01.php?id=" . $id); 
exit(0);
?>

 

Now you see, i put the resize and crop script into the other coding, what happens is that the image added by the user goes into a new field INSTEAD of changing what's already in there, in other words it's not updating? i hope i have explained my problem enough. If anyone know how to get it to update correctly please help, thank you very much.

 

 

Link to comment
https://forums.phpfreaks.com/topic/263806-update-profile-picture/
Share on other sites

Because you're using the same query as your registration which INSERTS data as a new row.

 

if (count($setArray) > 0) {
    $setstr = join (', ', $setArray);
    $query ="INSERT INTO `companies` 
(company_name, what_services, website, contact_name, location, postcode, street1, street2, city, phone,phone2, email, premiumuser_description, username, password, salt, approved, upload) 
VALUES ('$company_name', '$what_services', '$website', '$contact_name', '$location', '$postcode', '$street1', '$street2', '$city', '$phone', '$phone2', '$email', '$premiumuser_description', '$username', 'SHA($password)', '$salt', '$approved', '$upload')";
    mysql_query($query); 
}

 

You will need to use UPDATE and a WHERE statement to resolve your issue.

<?PHP /* check if form was submitted */
if (isset($_POST['Submit'])){
$error_message = "";
/* This is the directory where images will be saved */
$target = "server path"; 
$target = $target . basename( $_FILES['upload']['name']); 
/* include validation script */
include ('php only scripts/validation.php');
$uploadDir = '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 = "/images/thumbs";  /*  thumbnail folder */
$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/";
	$s_path = "images/thumbs/";
	$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);
}else{ 
	//Gives and error if its not 
	$error_message .= "Sorry, there was a problem uploading your file."; 
} ?>

 

thats the bit i put in/added, how come the username, password, phone numbers, company description all update and not ADD a new field? but the image does?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.