Foros del Web » Programando para Internet » PHP »

PHP - Upload de Imagenes con Insert en BD

Estas en el tema de PHP - Upload de Imagenes con Insert en BD en el foro de PHP en Foros del Web. Buenas amigos, Tengo hecho un formulario en PHP para la inserción de registros en la base de MySQL. Esto lo hice utilizando la forma wizard ...
  #1 (permalink)  
Antiguo 03/07/2008, 12:28
 
Fecha de Ingreso: julio-2008
Mensajes: 57
Antigüedad: 15 años, 9 meses
Puntos: 0
PHP - Upload de Imagenes con Insert en BD

Buenas amigos,
Tengo hecho un formulario en PHP para la inserción de registros en la base de MySQL.

Esto lo hice utilizando la forma wizard de Dreamweaver, o sea el asistente de insercion de registros.

Hasta aqui todo bien.

Mi consulta es la siguiente:

Como puedo hacer para modificar este formulario y agregarle la caja de busqueda de examinar para poder buscar la imagen que quiero subir y que automaticamente el nombre de la foto quede insertado en el campo foto de mi base?

Les paso lo que tengo hasta ahora: Podran ayudarme?

<?php require_once('Connections/cnx_sergio.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$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 productos (titulo, sinopsis, foto, categoria, director, actores) VALUES (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['titulo'], "text"),
GetSQLValueString($_POST['sinopsis'], "text"),
GetSQLValueString($_POST['foto'], "text"),
GetSQLValueString($_POST['categoria'], "int"),
GetSQLValueString($_POST['director'], "int"),
GetSQLValueString($_POST['actores'], "text"));

mysql_select_db($database_cnx_sergio, $cnx_sergio);
$Result1 = mysql_query($insertSQL, $cnx_sergio) or die(mysql_error());

$insertGoTo = "ok.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_cnx_sergio, $cnx_sergio);
$query_rs_categorias = "SELECT * FROM categorias";
$rs_categorias = mysql_query($query_rs_categorias, $cnx_sergio) or die(mysql_error());
$row_rs_categorias = mysql_fetch_assoc($rs_categorias);
$totalRows_rs_categorias = mysql_num_rows($rs_categorias);

mysql_select_db($database_cnx_sergio, $cnx_sergio);
$query_rs_directores = "SELECT * FROM directores";
$rs_directores = mysql_query($query_rs_directores, $cnx_sergio) or die(mysql_error());
$row_rs_directores = mysql_fetch_assoc($rs_directores);
$totalRows_rs_directores = mysql_num_rows($rs_directores);
?><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Documento sin t&iacute;tulo</title>
<style type="text/css">
<!--
@import url("css/estilos.css");
-->
</style>
</head>

<body>
<p class="Texto2">Alta de Registros (Pel&iacute;culas)</p>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td align="right" nowrap class="Texto3">Titulo:</td>
<td class="cajas"><input type="text" name="titulo" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap class="Texto3">Sinopsis:</td>
<td class="cajas"><input type="text" name="sinopsis" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap class="Texto3">Foto:</td>
<td class="cajas"><input type="text" name="foto" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap class="Texto3">Categoria:</td>
<td class="cajas"><select name="categoria">
<?php
do {
?>
<option value="<?php echo $row_rs_categorias['c_id']?>" ><?php echo $row_rs_categorias['c_nombre']?></option>
<?php
} while ($row_rs_categorias = mysql_fetch_assoc($rs_categorias));
?>
</select></td>
<tr>
<tr valign="baseline">
<td align="right" nowrap class="Texto3">Director:</td>
<td class="cajas"><select name="director">
<?php
do {
?>
<option value="<?php echo $row_rs_directores['d_id']?>" ><?php echo $row_rs_directores['d_nombre']?></option>
<?php
} while ($row_rs_directores = mysql_fetch_assoc($rs_directores));
?>
</select></td>
<tr>
<tr valign="baseline">
<td align="right" nowrap class="Texto3">Actores:</td>
<td class="cajas"><input type="text" name="actores" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap class="Texto3">&nbsp;</td>
<td class="cajas"><input type="submit" value="Insertar registro"></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
<p class="Texto4"><a href="index.html" target="_self">Home</a></p>
</body>
</html>
<?php
mysql_free_result($rs_categorias);

mysql_free_result($rs_directores);
?>
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 10:23.