Jump to content

Archived

This topic is now archived and is closed to further replies.

goldenbrown21

UPDATE command not working

Recommended Posts

Hi all!!!

 

Has ne1 got a script that allows them to upload images and UPDATE MYSQL db with the filename? I am stumped as to why this script won't UPDATE. Uploading the images is working.

 

My script:

 

<?php require_once('../Connections/conn_peninsula.php'); ?>
<?php
$colname_rs_uploadimage1 = "1";
if (isset($_GET['ID'])) {
$colname_rs_uploadimage1 = (get_magic_quotes_gpc()) ? $_GET['ID'] : addslashes($_GET['ID']);
}
mysql_select_db($database_conn_peninsula, $conn_peninsula);
$query_rs_uploadimage1 = sprintf("SELECT ID, Image1 FROM tbl_product WHERE ID = %s", $colname_rs_uploadimage1);
$rs_uploadimage1 = mysql_query($query_rs_uploadimage1, $conn_peninsula) or die(mysql_error());
$row_rs_uploadimage1 = mysql_fetch_assoc($rs_uploadimage1);
$totalRows_rs_uploadimage1 = mysql_num_rows($rs_uploadimage1);
?>
<form enctype="multipart/form-data" action="uploadimage1.php" method="POST" name="upload_file"> 
<input type="hidden" name="MAX_FILE_SIZE" value="5000000"> 
<input name="image1" type="file" id="image1" value="<?php echo $row_rs_uploadimage1['Image1']; ?>"> 
<input type="submit" value="upload" name="file_uploaded"> 
<input name="id" type="hidden" id="id" value="<?php echo $row_rs_uploadimage1['ID']; ?>">
<input type="hidden" name="MM_update" value="upload_file">
</form> 

upload.php:
<?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;
}

if (is_uploaded_file($_FILES['image1']['tmp_name'])) 
{ 
$file_realname = $_FILES['image1']['name']; 

copy($_FILES['image1']['tmp_name'], ".../images/$file_realname"); 
} else 
{ 
echo "<b><font color=red>No file uploaded.</font></b>"; } 
[COLOR=red]updateSQL = sprintf("UPDATE tbl_product SET Image1='$filename_realname' WHERE id=%s",
GetSQLValueString($_POST['ID'], "int"));
mysql_select_db($database_conn_peninsula, $conn_peninsula);
$Result1 = mysql_query($updateSQL, $conn_peninsula) or die(mysql_error());
mysql_free_result($rs_uploadimage1);[/COLOR]?>

If ne1 can shed some light, that would be excellent, as I hav searched the web for a script but have found none.

 

G :huh:

Share this post


Link to post
Share on other sites

Laying out your functions in some kind of order would help. Is this one script or 2? If one where is uploadimage1.php? Also why specify a MAX_FILESIZE if you dont use it in your script. Lay out your code in the order they are intended to work in balanced brackets and the code will work.

 

 <form enctype="multipart/form-data" action="uploadimage1.php" 

 

 

Also in the code below you are trying to update a table with infomation if a file is NOT uploaded.

 

if (is_uploaded_file($_FILES['image1']['tmp_name'])) 
{ 
$file_realname = $_FILES['image1']['name']; 

copy($_FILES['image1']['tmp_name'], ".../images/$file_realname"); 
} else 
{ 
echo "<b><font color=red>No file uploaded.</font></b>"; } 
[COLOR=red]updateSQL = sprintf("UPDATE tbl_product SET Image1='$filename_realname' WHERE id=%s",
GetSQLValueString($_POST['ID'], "int"));
mysql_select_db($database_conn_peninsula, $conn_peninsula);
$Result1 = mysql_query($updateSQL, $conn_peninsula) or die(mysql_error());

Share this post


Link to post
Share on other sites

×

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.