Me esta volviendo loco este IF, lo que quiero hacer es que si el campo $nombre_img llegue vacio no me inserte el campo "imagen" y me escriba en la bd "noimage.jpg", lo tengo echo asi...
Código PHP:
srand (time());
//generamos un número aleatorio
$mismo=str_replace(" ","_",$mismo);
$mismo = rand(1,100000000000);
$nombre_img = str_replace(" ","",$_FILES['imagen'] ['name']);
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if (($nombre_img)!="") {
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE articulos SET articulo=%s, argrupo=%s, arforma=%s, quien=%s, precio=%s, imagenarticulo=%s, ud=%s WHERE id_articulos=%s",
GetSQLValueString($_POST['articulo'], "text"),
GetSQLValueString($_POST['grupo'], "int"),
GetSQLValueString($_POST['forma'], "int"),
GetSQLValueString($_POST['quien'], "text"),
GetSQLValueString($_POST['precio'], "double"),
GetSQLValueString("../archivos/".$mismo.$nombre_img, "text"),
GetSQLValueString($_POST['uc'], "int"),
GetSQLValueString($_POST['id'], "int"));
$copy = copy($_FILES['imagen']['tmp_name'], "../archivos/" .$mismo .$nombre_img);
}
else {
$updateSQL = sprintf("UPDATE articulos SET articulo=%s, argrupo=%s, arforma=%s, quien=%s, precio=%s, imagenarticulo=%s, ud=%s WHERE id_articulos=%s",
GetSQLValueString($_POST['articulo'], "text"),
GetSQLValueString($_POST['grupo'], "int"),
GetSQLValueString($_POST['forma'], "int"),
GetSQLValueString($_POST['quien'], "text"),
GetSQLValueString($_POST['precio'], "double"),
GetSQLValueString("../archivos/noimage.jpg", "text"),
GetSQLValueString($_POST['uc'], "int"),
GetSQLValueString($_POST['id'], "int"));
}
mysql_select_db($database_deume, $deume);
$Result1 = mysql_query($updateSQL, $deume) or die(mysql_error());
$updateGoTo = "mod_articulo.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
Código PHP:
<form action="<?php echo $editFormAction; ?>" id="form1" name="form1" method="POST" enctype="multipart/form-data">
<table width="635">
<tr>
<td width="127">Articulo:</td>
<td width="285"><input name="articulo" type="text" id="articulo" value="<?php echo $row_articulo['articulo']; ?>" /></td>
<td width="102"><a href="<?php printf("%s?pageNum_articulo=%d%s", $currentPage, min($totalPages_articulo, $pageNum_articulo + 1), $queryString_articulo); ?>">Siguiente</a></td>
<td width="103"><a href="<?php printf("%s?pageNum_articulo=%d%s", $currentPage, max(0, $pageNum_articulo - 1), $queryString_articulo); ?>">Anterior</a></td>
</tr>
<tr>
<td>Grupo:</td>
<td><select name="grupo" id="grupo">
<?php
do {
?>
<option value="<?php echo $row_grupo['id_grupo']?>"<?php if (!(strcmp($row_grupo['id_grupo'], $row_articulo['argrupo']))) {echo "selected=\"selected\"";} ?>><?php echo $row_grupo['grupo']?></option>
<?php
} while ($row_grupo = mysql_fetch_assoc($grupo));
$rows = mysql_num_rows($grupo);
if($rows > 0) {
mysql_data_seek($grupo, 0);
$row_grupo = mysql_fetch_assoc($grupo);
}
?>
</select></td>
<td colspan="2"> </td>
</tr>
<tr>
<td>Presentación:</td>
<td><select name="forma" id="forma">
<?php
do {
?><option value="<?php echo $row_forma['id_forma']?>"<?php if (!(strcmp($row_forma['id_forma'], $row_articulo['arforma']))) {echo "selected=\"selected\"";} ?>><?php echo $row_forma['forma']?></option>
<?php
} while ($row_forma = mysql_fetch_assoc($forma));
$rows = mysql_num_rows($forma);
if($rows > 0) {
mysql_data_seek($forma, 0);
$row_forma = mysql_fetch_assoc($forma);
}
?>
</select></td>
<td colspan="2"> </td>
</tr>
<tr>
<td>Proveedor</td>
<td><select name="quien" id="quien">
<option value="G" <?php if (!(strcmp("G", $row_articulo['quien']))) {echo "selected=\"selected\"";} ?>>INTERNO</option>
<option value="S" <?php if (!(strcmp("S", $row_articulo['quien']))) {echo "selected=\"selected\"";} ?>>EXTERNO</option>
</select></td>
<td colspan="2"> </td>
</tr>
<tr>
<td>Imagen:</td>
<td><input name="imagen" type="file" id="imagen" value="" /></td>
<td colspan="2"> </td>
</tr>
<tr>
<td>Precio:</td>
<td><input name="precio" type="text" id="precio" value="<?php echo $row_articulo['precio']; ?>" size="4" />
€</td>
<td colspan="2"><input name="id" type="hidden" id="id" value="<?php echo $row_articulo['id_articulos']; ?>" /></td>
</tr>
<tr>
<td>Unidades:</td>
<td><label>
<input name="uc" type="text" id="uc" value="<?php echo $row_articulo['ud']; ?>" size="4" />
</label></td>
<td colspan="2">Unidades por envase</td>
</tr>
<tr>
<td> </td>
<td><label>
<input name="button" type="submit" class="boton" id="button" value="MODIFICAR ARTICULO" />
</label></td>
<td colspan="2"> </td>
</tr>
</table>
<input type="hidden" name="MM_update" value="form1" />
</form>
Alguien me puede ayudar?
Un saludo