a browse and submit button when pick the image and submit , the image name goes to my SQL table and the image it self that the customer pick it copied to my "upload" folder :(

my problem is that i only see the image name , so my issue is that i can't upload that image to a Folder :S

the code is :

<?php require_once('Connections/dalilack.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);

}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO packages (packageTitle, packageDescription, packageGraphic) VALUES (%s, %s, %s)",
                       GetSQLValueString($_POST['packageTitle'], "text"),
                       GetSQLValueString($_POST['packageDescription'], "text"),
                       GetSQLValueString($_POST['packageGraphic'], "text"));



  mysql_select_db($database_dalilack, $dalilack);
  $Result1 = mysql_query($insertSQL, $dalilack) or die(mysql_error());

$target_path = "upload/".$_FILES['packageGraphic']['name'];
move_uploaded_file($_FILES['packageGraphic']['tmp_name'],$target_path);
  $insertGoTo = "marketList.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_dalilack, $dalilack);
$query_product = "SELECT packageId, packageTitle, packageDescription, packageGraphic FROM packages";
$product = mysql_query($query_product, $dalilack) or die(mysql_error());
$row_product = mysql_fetch_assoc($product);
$totalRows_product = mysql_num_rows($product);

?>

<!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>
<title>Portfolio</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="style.css" rel="stylesheet" type="text/css" />
<link href="stylesheets/screen.css" type="text/css" rel="stylesheet" media="screen,projection" />
<script type="text/javascript" src="scripts/jquery.js"></script>
<script type="text/javascript" src="scripts/framework.js"></script>
<!--[if lt IE 7]>
<link href="stylesheets/screen-ie6.css" type="text/css" rel="stylesheet" media="screen,projection" />
<![endif]-->
</head>
<body>
<div class="main">
  <div class="header_full">
    <div class="header">
      <div class="twitter"><a href="index.html"><img src="images/twitter.gif" width="38" height="35" border="0" alt="logo" /></a><span>Follow us on Twitter</span></div>
      <div class="top_menu"><a href="#">Email</a> | <a href="#">Client Login</a></div>
      <div class="clr"></div>
      <div class="logo"><a href="index.html"><img src="images/logo2.png" width="249" height="71" border="0" alt="logo" /></a></div>
      <div class="menu">
        <ul>
          <li><a href="index.html"><span>home</span></a></li>
          <li><a href="portfolio.html" class="active"><span>portfolio</span></a></li>
          <li><a href="about.html"><span>about me</span></a></li>
          <li><a href="contact.html"><span>contact me</span></a></li>
        </ul>
      </div>
      <div class="clr"></div>
    </div>
  </div>
  <div class="body">
    <div class="block_box">
      <div class="block_box_t">
        <div class="block_box_b">
          <h1 class="about">E-Market : Click then Post !!</h1>
         
<div id="container">

	<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
	  <table align="center">
	    <tr valign="baseline">
	      <td nowrap="nowrap" align="right">PackageTitle:</td>
	      <td><input type="text" name="packageTitle" value="" size="32" /></td>
	      </tr>
	    <tr valign="baseline">
	      <td nowrap="nowrap" align="right">PackageDescription:</td>
	      <td><input type="text" name="packageDescription" value="" size="32" /></td>
	      </tr>
	    <tr valign="baseline">
	      <td nowrap="nowrap" align="right">PackageGraphic:</td>
	      <td><input type="file" name="packageGraphic" id="upload"  value="" size="32"  /></td>
	      </tr>
	    <tr valign="baseline">
	      <td nowrap="nowrap" align="right">&nbsp;</td>
	      <td><input type="submit" value="Insert record" /></td>
	      </tr>
	    </table>
	  <input type="hidden" name="MM_insert" value="form1" />
	  </form>
	<p>
    </p>
</div>

          <div class="clr"></div>
        </div>
      </div>
    </div>
  </div>
  <div class="footer">
    <div class="footer_resize">
      <p class="leftt"><a href="index.html"><img src="images/logo_f.png" alt="picture" width="249" height="71" border="0" /></a></p>
      <p class="rightt">© Copyright Dalilack.com. <a href="http://dalilack.com/" class="no_border">dalilack.com</a>. All Rights Reserved</p>
      <div class="clr"></div>
    </div>
  </div>
  <div class="clr"></div>
</div>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($product);
?>

thank you

Recommended Answers

All 6 Replies

Member Avatar for diafol
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">

you haven't got an enctype attribute.

Put this in:

enctype="multipart/form-data"
commented: yes +5

i have already put it , and it gaves me error


( ! ) Notice: Undefined index: packageGraphic in C:\wamp\www\Dalilack\marketProduct.php on line 43
Call Stack
# Time Memory Function Location
1 0.0010 400440 {main}( ) ..\marketProduct.php:0
Column 'packageGraphic' cannot be null

i have found a solution but there's a lil tiny problem
first of all here's my new code

<?php require_once('Connections/dalilack.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);

}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO packages (packageTitle, packageDescription, packageGraphic) VALUES (%s, %s, %s)",
                       GetSQLValueString($_POST['packageTitle'], "text"),
                       GetSQLValueString($_POST['packageDescription'], "text"),
                       GetSQLValueString($_POST['packageGraphic'], "text"));



  mysql_select_db($database_dalilack, $dalilack);

$type     = $_FILES["image"]["type"];
$name     = $_FILES["image"]["name"];
$tmp_name = $_FILES["image"]["tmp_name"]; 
$image_directory = "upload";
$img_path="$image_directory/".$name;
$uploadimage = copy($tmp_name,$img_path);
  
  $insertGoTo = "marketList.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_dalilack, $dalilack);
$query_product = "SELECT packageId, packageTitle, packageDescription, packageGraphic FROM packages";
$product = mysql_query($query_product, $dalilack) or die(mysql_error());
$row_product = mysql_fetch_assoc($product);
$totalRows_product = mysql_num_rows($product);

?>

<!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>
<title>Portfolio</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="style.css" rel="stylesheet" type="text/css" />
<link href="stylesheets/screen.css" type="text/css" rel="stylesheet" media="screen,projection" />
<script type="text/javascript" src="scripts/jquery.js"></script>
<script type="text/javascript" src="scripts/framework.js"></script>
<script language="javascript" type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script src="jquery.MultiFile.js" type="text/javascript" language="javascript"></script>

<!--[if lt IE 7]>
<link href="stylesheets/screen-ie6.css" type="text/css" rel="stylesheet" media="screen,projection" />
<![endif]-->
</head>
<body>
<div class="main">
  <div class="header_full">
    <div class="header">
      <div class="twitter"><a href="index.html"><img src="images/twitter.gif" width="38" height="35" border="0" alt="logo" /></a><span>Follow us on Twitter</span></div>
      <div class="top_menu"><a href="#">Email</a> | <a href="#">Client Login</a></div>
      <div class="clr"></div>
      <div class="logo"><a href="index.html"><img src="images/logo2.png" width="249" height="71" border="0" alt="logo" /></a></div>
      <div class="menu">
        <ul>
          <li><a href="index.html"><span>home</span></a></li>
          <li><a href="portfolio.html" class="active"><span>portfolio</span></a></li>
          <li><a href="about.html"><span>about me</span></a></li>
          <li><a href="contact.html"><span>contact me</span></a></li>
        </ul>
      </div>
      <div class="clr"></div>
    </div>
  </div>
  <div class="body">
    <div class="block_box">
      <div class="block_box_t">
        <div class="block_box_b">
          <h1 class="about">E-Market : Click then Post !!</h1>
         
<div id="container">

	<form action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" name="form1" id="form1">
    <script type='text/javascript'>
			$.fn.MultiFile.options.accept = 'png|gif|jpg|jpeg';
			$.fn.MultiFile.options.max     = 1;
		</script>
	  <table align="center">
	    <tr valign="baseline">
	      <td nowrap="nowrap" align="right">PackageTitle:</td>
	      <td><input type="text" name="packageTitle" value="" size="32" /></td>
	      </tr>
	    <tr valign="baseline">
	      <td nowrap="nowrap" align="right">PackageDescription:</td>
	      <td><input type="text" name="packageDescription" value="" size="32" /></td>
	      </tr>
	    <tr valign="baseline">
	      <td nowrap="nowrap" align="right">PackageGraphic:</td>
	      <td> <input type="file" name="packageGraphic" id="upload"  value="" size="32"  />
          <input type="file" name="image" id="upload"  value="" size="32"  /></td>
	      </tr>
	    <tr valign="baseline">
	      <td nowrap="nowrap" align="right">&nbsp;</td>
	      <td><input name="Submit" type="submit" id="Submit" value="Insert record" /></td>
	      </tr>
	    </table>
	  <input type="hidden" name="MM_insert" value="form1" />
	  </form>

	<p>
    </p>
</div>

          <div class="clr"></div>
        </div>
      </div>
    </div>
  </div>
  <div class="footer">
    <div class="footer_resize">
      <p class="leftt"><a href="index.html"><img src="images/logo_f.png" alt="picture" width="249" height="71" border="0" /></a></p>
      <p class="rightt">© Copyright Dalilack.com. <a href="http://dalilack.com/" class="no_border">dalilack.com</a>. All Rights Reserved</p>
      <div class="clr"></div>
    </div>
  </div>
  <div class="clr"></div>
</div>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($product);
?>

now i need to show only one input ""In condition"" :

<input type="file" name="packageGraphic" id="upload"  value="" size="32"  />

this one is hidden

= Equal =

<input type="file" name="image" id="upload"  value="" size="32"  />

so that when the i press on browse the image name will be in the first input and on submit image name goes to my SQL

and the second input at the same time when press on Browse again the image will be copied and directed to the path folder

i have did it well , but now all i need is to do this <input ONE> = <input TWO>

Member Avatar for diafol

I can't see why you need to do this. I haven't read ALL the code, but I can't see why you need a second field for the sql name - just get it from the filename you upload $_FILES

PROBLEM SOLVED THANKS MAN :D
i add name into this code GetSQLValueString($_FILES, "text"));

and done :D
thanks again

Member Avatar for diafol

OK, mark as solved (link below the box).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.