Link to home
Start Free TrialLog in
Avatar of phillystyle123
phillystyle123Flag for United States of America

asked on

upload image script in tandem with update database script

I'm using update sql to update my db. This works fine until I try to incorporate upload image code - which also works fine by itself. It appears as though the upload image code isn't even being recognized - not sure what i'm doing wrong
<?php require_once('../../Connections/connSmartBenefit.php'); ?>
<?php $dir=$_GET['directory_name'];?>
<?
//BEGIN UPLOAD IMAGE SCRIPT
//print_r($_POST);

if($_POST["action"] == "Upload Image")
{
unset($imagename);

if(!isset($_FILES) && isset($HTTP_POST_FILES))
$_FILES = $HTTP_POST_FILES;

if(!isset($_FILES['image_file']))
$error["image_file"] = "An image was not found.";


$imagename = basename($_FILES['image_file']['name']);
//echo $imagename;

if(empty($imagename))
$error["imagename"] = "The name of the image was not found.";

if(empty($error))
{
$newimage = "/home/smarter/public_html/".$dir."/images/" . $imagename;
//echo $newimage;
$result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage);
if(empty($result))
$error["result"] = "There was an error moving the uploaded file.";
}

}
//END UPLOAD IMAGE SCRIPT
?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
//BEGIN UPDATE DB SCRIPT
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "step2")) {
  $updateSQL = sprintf("UPDATE company_info SET logo=%s WHERE directory_name=%s",
                       GetSQLValueString($_POST['logo'], "text"),
                       GetSQLValueString($_POST['directory_name'], "text"));

  mysql_select_db($database_connSmartBenefit, $connSmartBenefit);
  $Result1 = mysql_query($updateSQL, $connSmartBenefit) or die(mysql_error());

  $updateGoTo = "step3.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}
//END UPDATE IMAGE SCRIPT
 $crumb="new";?>
<?php $crumb2="step2";?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?php include('../includes/browser_title.php');?></title>
<link href="../admin.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="wrap">

<div id="contentWrap">
<?php include('../includes/admin_title.php');?>
<h2 align="center"><a href="../main_menu.php">Main Menu</a> > Create New Account</h2>
<?php include('../includes/steps.php');?>
<form enctype="multipart/form-data" action="<?php echo $editFormAction; ?>"  id="step2" name="step2" method="POST">
<p>Upload account company logo. 
<div class="formRow">
<label><strong>Logo:</strong>
<input class="input1" name="logo" type="file" id="logo" />
</label>
<input name="directory_name" type="text" id="directory_name" value="<?php echo $_GET['directory_name'];?>" />
</div>

<div class="formRow">new image: <?php echo $newimage;?></div>

  <input class="submit"  type="submit"  value="Upload Image" name="action"/>
  <input type="hidden" name="MM_update" value="step2">
</form>

<?
if(is_array($error))
{
while(list($key, $val) = each($error))
{
echo $val;
echo "<br>\n";
}
}
?>

</div>


</body>

</html>

Open in new window

SOLUTION
Avatar of NerdsOfTech
NerdsOfTech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of phillystyle123

ASKER

thanks for helping - nothing changed yet - added php to <? and echo 'test output'; outputs absolutely nothing. it's like this upload script isn't being seen. when i use it by itself it uploads, works like a charm - when i use in tandom with my update code, it disappears
<?php require_once('../../Connections/connSmartBenefit.php'); ?>
<?php $dir=$_GET['directory_name'];?>
<?php
//BEGIN UPLOAD IMAGE SCRIPT
//print_r($_POST);

if($_POST["action"] == "Upload Image")
{
unset($imagename);

if(!isset($_FILES) && isset($HTTP_POST_FILES))
$_FILES = $HTTP_POST_FILES;

if(!isset($_FILES['image_file']))
$error["image_file"] = "An image was not found.";


$imagename = basename($_FILES['image_file']['name']);
//echo $imagename;

if(empty($imagename))
$error["imagename"] = "The name of the image was not found.";

if(empty($error))
{
$newimage = "/home/smarter/public_html/".$dir."/images/" . $imagename;
//echo $newimage;
$result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage);
if(empty($result))
$error["result"] = "There was an error moving the uploaded file.";
}
echo 'test output';

}
//END UPLOAD IMAGE SCRIPT
?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
//BEGIN UPDATE DB SCRIPT
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "step2")) {
  $updateSQL = sprintf("UPDATE company_info SET logo=%s WHERE directory_name=%s",
                       GetSQLValueString($_POST['logo'], "text"),
                       GetSQLValueString($_POST['directory_name'], "text"));

  mysql_select_db($database_connSmartBenefit, $connSmartBenefit);
  $Result1 = mysql_query($updateSQL, $connSmartBenefit) or die(mysql_error());

  $updateGoTo = "step3.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}
//END UPDATE IMAGE SCRIPT
 $crumb="new";?>
<?php $crumb2="step2";?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?php include('../includes/browser_title.php');?></title>
<link href="../admin.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="wrap">

<div id="contentWrap">
<?php include('../includes/admin_title.php');?>
<h2 align="center"><a href="../main_menu.php">Main Menu</a> > Create New Account</h2>
<?php include('../includes/steps.php');?>
<form enctype="multipart/form-data" action="<?php echo $editFormAction; ?>"  id="step2" name="step2" method="POST">
<p>Upload account company logo. 
<div class="formRow">
<label><strong>Logo:</strong>
<input class="input1" name="logo" type="file" id="logo" />
</label>
<input name="directory_name" type="text" id="directory_name" value="<?php echo $_GET['directory_name'];?>" />
</div>

<div class="formRow">new image: <?php echo $newimage;?></div>

  <input class="submit"  type="submit"  value="Upload Image" name="action"/>
  <input type="hidden" name="MM_update" value="step2">
</form>

<?
if(is_array($error))
{
while(list($key, $val) = each($error))
{
echo $val;
echo "<br>\n";
}
}
?>

</div>


</body>

</html>

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i'm getting 2 errors - this at the top of the page:

Warning: Cannot modify header information - headers already sent by (output started at /home/smarter/public_html/admin/new/step2.php:4) in /home/smarter/public_html/admin/new/step2.php on line 48
test output

and this at the bottom:

An image was not found.
The name of the image was not found.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial