Mi consulta es la siguiente: yo necesito actualizar unos datos del servidor, y todo funciona perfectamente, hasta que incorporo la posibilidad de actualizar tambien el archivo vinculado a cada registro.
El codigo que utilizo es:
Código PHP:
<?php require_once('../../Connections/config.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;
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ( $archivo != "none" )
{
$fp = fopen($archivo, "rb");
$contenido = @fread($fp, $tamanio);
$contenido = addslashes($contenido);
@fclose($fp);
}
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE news SET title=%s, summary=%s, text=%s, author=%s, organization=%s, $nombre=%s, $contenido=%s, $tipo=%s WHERE id=%s",
GetSQLValueString($_POST['title'], "text"),
GetSQLValueString($_POST['summary'], "text"),
GetSQLValueString($_POST['text'], "text"),
GetSQLValueString($_POST['author'], "text"),
GetSQLValueString($_POST['organization'], "text"),
$archivo = $_FILES["archivo"]["tmp_name"],
$tamanio = $_FILES["archivo"]["size"],
$tipo = $_FILES["archivo"]["type"],
$nombre = $_FILES["archivo"]["name"],
GetSQLValueString($_POST['id'], "int"));
move_uploaded_file($HTTP_POST_FILES['archivo']['tmp_name'], "files/$nombre");
mysql_select_db($database_config, $config);
$Result1 = mysql_query($updateSQL, $config) or die(mysql_error());
$updateGoTo = "ind_news.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
$colname_news = "1";
if (isset($_GET['recordID'])) {
$colname_news = (get_magic_quotes_gpc()) ? $_GET['recordID'] : addslashes($_GET['recordID']);
}
mysql_select_db($database_config, $config);
$query_news = sprintf("SELECT * FROM news WHERE id = %s", $colname_news);
$news = mysql_query($query_news, $config) or die(mysql_error());
$row_news = mysql_fetch_assoc($news);
$totalRows_news = mysql_num_rows($news);
?>
y me da este error:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '=, =0, = WHERE id=' at line 1
he probado de mil maneras y no consigo que funcione correctamente, si alguien me puede ayudar se lo agradeceria
Un saludo