Hi All
I think this is my last problem with this site. On the admin side of the site is a update form. All data updates fine when it is changed, however when selecting a new image, it doesn't upload or add the filename to the DB.
I have tried combining two separate scripts but can't get it to work. My limited PHP knowledge wont let me adapt the code to make it work.
I have attached the PHP code in the hope that somebody can show me the error of my ways. I apologise in advance for my very poor code.
Thanks
<?php require_once('Connections/xxxxxxxx.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_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE WickerOutdoor SET ProductName=%s, Materials=%s, P_sizeOne=%s, P_sizeTwo=%s, P_sizeThr=%s, P_sizeFour=%s, Colour=%s, Description=%s, Dimensions=%s, PriceOne=%s, PriceTwo=%s, PriceThr=%s, PriceFour=%s WHERE idProdCode=%s",
GetSQLValueString($_POST['ProductName'], "text"),
GetSQLValueString($_POST['Materials'], "text"),
GetSQLValueString($_POST['P_sizeOne'], "text"),
GetSQLValueString($_POST['P_sizeTwo'], "text"),
GetSQLValueString($_POST['P_sizeThr'], "text"),
GetSQLValueString($_POST['P_sizeFour'], "text"),
GetSQLValueString($_POST['Colour'], "text"),
GetSQLValueString($_POST['Description'], "text"),
GetSQLValueString($_POST['DImensions'], "text"),
GetSQLValueString($_POST['PriceOne'], "int"),
GetSQLValueString($_POST['PriceTwo'], "int"),
GetSQLValueString($_POST['PriceThr'], "int"),
GetSQLValueString($_POST['PriceFour'], "int"),
GetSQLValueString($_POST['idProdCode'], "int"));
mysql_select_db($database_xxxxx, $xxxxx);
$Result1 = mysql_query($updateSQL, $xxxxxx) or die(mysql_error());
$updateGoTo = "wicker_view2.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
$colname_rsWickerDown = "-1";
if (isset($_GET['ID'])) {
$colname_rsWickerDown = $_GET['ID'];
}
mysql_select_db($database_xxxxx, $xxxx);
$query_rsWickerDown = sprintf("SELECT * FROM WickerOutdoor WHERE idProdCode = %s", GetSQLValueString($colname_rsWickerDown, "int"));
$rsWickerDown = mysql_query($query_rsWickerDown, $casalivi_CASA) or die(mysql_error());
$row_rsWickerDown = mysql_fetch_assoc($rsWickerDown);
$totalRows_rsWickerDown = mysql_num_rows($rsWickerDown);$colname_rsWickerDown = "-1";
if (isset($_GET['ID'])) {
$colname_rsWickerDown = $_GET['ID'];
}
mysql_select_db($database_xxxxx, $xxxxxx);
$query_rsWickerDown = sprintf("SELECT * FROM WickerOutdoor WHERE idProdCode = %s", GetSQLValueString($colname_rsWickerDown, "int"));
$rsWickerDown = mysql_query($query_rsWickerDown, $casalivi_CASA) or die(mysql_error());
$row_rsWickerDown = mysql_fetch_assoc($rsWickerDown);
$totalRows_rsWickerDown = mysql_num_rows($rsWickerDown);
?>
<?php
$uploadDir = 'img/';
if(isset($_POST['upload']))
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$filePath = $uploadDir . $fileName;
$result = move_uploaded_file($tmpName, $filePath);
if (!$result) {
echo "Error uploading file";
exit;
}
mysql_select_db($database_xxxxxxx, $xxxxxx);
//include '../library/config.php';
//include '../library/opendb.php';
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$filePath = addslashes($filePath);
}
$query = "UPDATE INTO WickerOutdoor (name, size, type, name_loc ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$filePath')";
mysql_query($query) or die('Error, query failed : ' . mysql_error());
//include '../library/closedb.php';
echo "<br>Files uploaded<br>";
}
?>