El problema es como los adapto al codigo para insertar datos del Dreamweaver (DW)? Es Decir...
Yo hago un formulario en DW, luego agrego un comportamiento de servidor (comando/función de DW) lo que hace es escribir el codigo correspondiente para insertar los datos.... y lo hace a la perfección!
El problema esta cuando...
...quiero adaptar uno de los codigos de subir imagenes a una carpeta y guardar la ruta en un campo (en este caso form_imagen1)
Intentos...
He logrado insertarlos en la carpeta pero no guarda la ruta, me da error que dice: no puede ser el valor NULL
Entonces reviso el codigo y me encuentro primero con una función que le doy vueltas y no consigo entenderla GetSQLValueString
Es cuando empiezo a querer adaptar el código de insertar imágenes al código que genera Dreamweaver...
Qué codigo quiero adaptar?
Bueno en principio diría cualquiera pero, lo que busco en realidad es
- asignar un valor maximo en Bytes para la imagen.
- asignar un nombre con el Id del registro + un número autoincrementable, si un usuario y/o cliente tiene 3 imagenes sería así: 3_1.jpg, 3_2.jpg, 3_3_jpg
El primer número 3 indíca que es el usuario número 3 y los otros el número de la imagen de ese usuario. (si hay otra idea mejor!)
- y no se si hay otra cosa que deba hacer para que sea segura la transacción.
Esto es lo que estoy utilizando!!!
Código PHP:
<?php
//INICIO DEL DOLOR DE CABEZA -------------------------------------------------------------------------
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 ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "enviar")) {
$insertSQL = sprintf("INSERT INTO prueba01 (id_prueba1, dato_prueba1, imagen1) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['id_prueba1'], "int"),
GetSQLValueString($_POST['dato_prueba1'], "text"),
GetSQLValueString($_POST['form_imagen1'], "text"));
mysql_select_db($database_gcd, $gcd);
$Result1 = mysql_query($insertSQL, $gcd) or die(mysql_error());
}
// FIN DEL DOLOR DE CABEZA ---------------------------------------------------------------------------
// Como Adapto este formulario para que suba imágenes??
// (INICIO) CONSULTA DE MAXIMOS IDS----------------------------------------------------------------------
mysql_select_db($database_gcd, $gcd);
$query_maximos1y2 = "SELECT max(id_prueba1), max(id_prueba2) FROM prueba01, prueba02";
$maximos1y2 = mysql_query($query_maximos1y2, $gcd) or die(mysql_error());
$row_maximos1y2 = mysql_fetch_assoc($maximos1y2);
$totalRows_maximos1y2 = mysql_num_rows($maximos1y2);
// (FIN) CONSULTA DE MAXIMOS IDS --------------------------------------------------------------------------?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Documento sin título</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="enviar" id="enviar"POST>
<p>Dato en tabla01
<input name="dato_prueba1" type="text" id="dato_prueba1" size="10" maxlength="10">
<input name="id_prueba1" type="hidden" id="id_prueba1" value="<?php echo $row_maximos1y2['max(id_prueba1)']; ?>">
</p>
<p>Dato en tabla02
<input name="dato_prueba2" type="text" id="dato_prueba2" size="10" maxlength="10">
<input name="id_prueba2" type="hidden" id="id_prueba2" value="<?php echo $row_maximos1y2['max(id_prueba2)']; ?>">
</p>
<p>Imagen:
<input name="form_imagen1" type="file" id="form_imagen1">
</p>
<p> </p>
<p>
<input name="Submit_enviar" type="submit" id="Submit_enviar" value="Enviar">
</p>
<input type="hidden" name="MM_insert" value="enviar">
</form>
</body>
</html>
<?php
mysql_free_result($maximos1y2);
?>
Solo llevo un Mes con esto del PHP/MySQL, soy medio aplicado pero mis fuertes son: AutoCAD, 3dsmax, Photoshop yle doy más o menos al Flash
Espero ayudar en los próximos meses a ver que tal!!!
Para ser sincero pensé que estos foros no servían y que no respondían los mensajes!!!
Falta de experiencia no?
Buenos Saludos y gracias dfe antemano