Ver Mensaje Individual
  #7 (permalink)  
Antiguo 04/04/2007, 17:19
Induma
 
Fecha de Ingreso: enero-2004
Ubicación: en mi casa
Mensajes: 29
Antigüedad: 20 años, 3 meses
Puntos: 1
Re: subir imagen y añadir la ruta a BD

el codigo es el de arriba, no crei necesario poner un codigo erroneo
tampoco lo he pedido ya hecho, solo saber como hacerlo, que deberia modificar tanto en el codigo como en la BD para que funcionase. ya que en todos los codigos que he visto es necesario otro archivo php para realizar el upload y eso es algo que me gustaria evitar

el codigo erroneo es este:

Código:
<html>
<head>
<title>Insertar Recetas</title>
<?php require_once('../../Connections/recetas.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 ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO comida (id, id_categoria, nombre, ingredientes, tiempo, imagen, receta) VALUES (%s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['id'], "int"),
                       GetSQLValueString($_POST['id_categoria'], "int"),
                       GetSQLValueString($_POST['nombre'], "text"),
                       GetSQLValueString($_POST['ingredientes'], "text"),
                       GetSQLValueString($_POST['tiempo'], "text"),
                       GetSQLValueString($_POST['imagen'], "text"),
                       GetSQLValueString($_POST['receta'], "text"));

  mysql_select_db($database_recetas, $recetas);
  $Result1 = mysql_query($insertSQL, $recetas) or die(mysql_error());

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

mysql_select_db($database_recetas, $recetas);
$query_Recordset1 = "SELECT * FROM comida";
$Recordset1 = mysql_query($query_Recordset1, $recetas) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<style type="text/css">
<!--
.Estilo1 {
	color: #CC0000;
	font-weight: bold;
}
.Estilo2 {font-size: large}
-->
</style>

<div align="center" class="Estilo1 Estilo2">
  <p>INSERTAR RECETAS</p>
</div>

    <form enctype="multipart/form-data" method="post" name="form1" action="<?php echo $editFormAction; ?>">
      <table align="center">
        <tr valign="baseline">
          <td nowrap align="right">Categoria:</td>
          <td><?php
echo '<select name="id_categoria">';
$resul = mysql_query("SELECT * FROM categoria WHERE 1");
while($fila = mysql_fetch_array($resul)){
    echo '<option value="' . $fila['id'] . '">' . $fila['nombre_categoria'] . '</option>';
}
echo '</select>';
?> </td>
        </tr>
        <tr valign="baseline">
          <td nowrap align="right">Nombre:</td>
          <td><input type="text" name="nombre" value="" size="36"></td>
        </tr>
        <tr valign="middleline">
          <td nowrap align="right">Ingredientes:</td>
          <td><textarea name="ingredientes" cols="32"></textarea></td>
        </tr>
        <tr valign="baseline">
          <td nowrap align="right">Tiempo:</td>
          <td><input type="text" name="tiempo" value="" size="36"></td>
        </tr>
        <tr valign="baseline">
          <td nowrap align="right">Imagen:</td>
          <td><input name="userfile" type="file" value="" size="36"></td>
        </tr>
        <tr valign="middleline">
          <td nowrap align="right">Receta:</td>
          <td><textarea name="receta" cols="32"></textarea></td>
        </tr>
        <tr valign="baseline">
          <td nowrap align="right">&nbsp;</td>
          <td><input type="submit" value="Insertar registro"></td>
        </tr>
      </table>
      <input type="hidden" name="MM_insert" value="form1">
    </form>
    <p>&nbsp;</p>
    <?php
mysql_free_result($Recordset1);
?>
como puedes comprobar es exactamente igual al anterior menos una linea, la del campo imagen
un saludo

INDUMA