Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

upload image script in tandem with update database script

Avatar of phillystyle123
phillystyle123Flag for United States of America asked on
PHP
8 Comments1 Solution484 ViewsLast Modified:
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>
ASKER CERTIFIED SOLUTION
Avatar of phillystyle123
phillystyle123Flag of United States of America image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answers