Hello,
Someone can give me a hand here with some code ? Nay help here would be great.
Thanks in advance
CODE OBJECTIVE:
Insert, delete and update a page where there are 5 images and a textarea for each one to input their respective keywords.
The INSERT page is working fine but this one isn't updating, or deleting, depending on what's done on it.
THE CODE: (already written)
<? include('includes/database.php');
if(isset($submit)){
UPDATE KEYWORDS
$sql ="UPDATE fotos_empreendimento SET empreendimentoID='$ID', key_foto1='$key_foto1New', key_foto2='$key_foto2New', key_foto3='$key_foto3New', key_foto4='$key_foto4New', key_foto5='$key_foto5New' WHERE empreendimentoID=$ID";
$result=mysql_query($sql) or die("UPDATE KEYWORDS".mysql_error());
INSERT/DELETE OR UPDATE PHOTOS
if($empr_foto1_name!="") {
$empr_foto1Extension=($empr_foto1_type=="image/gif")?"gif":"jpg";
$sql="SELECT empr_foto1 FROM fotos_empreendimento WHERE empreendimentoID=$ID";
$result=mysql_query($sql) or die($sql.":".mysql_error());
$campos=mysql_fetch_assoc($result);
@unlink("../images/empr/".$campos["empr_foto1"]);
copy ($empr_foto1,"../images/empr/foto_empr".$ID."1.".$empr_foto1Extension);
unlink($empr_foto1);
$empr_foto1Name="empr_foto1='foto_empr".$ID."1.".$empr_foto1Extension."'";
} else {
if($del_empr_foto1=="on") {
$empr_foto1Name="empr_foto1=null";
$sql="SELECT empr_foto1 FROM fotos_empreendimento WHERE empreendimentoID=$ID";
$result=mysql_query($sql);
$campos=mysql_fetch_assoc($result);
@unlink("../images/empr/".$campos["empr_foto1"]);
//$key_foto1New="key_foto1New=null";
} else {
$empr_foto1Name="";
//$key_foto1New="";
}
}
//$sql="UPDATE fotos_empreendimento SET $empr_foto1Name, key_foto1='$key_foto1New' WHERE empreendimentoID=$ID";
$sql="UPDATE fotos_empreendimento SET $empr_foto1Name WHERE empreendimentoID=$ID";
$result=mysql_query($sql) or die("$sql:".mysql_error());
if($empr_foto2_name!="") {
$empr_foto2Extension=($empr_foto2_type=="image/gif")?"gif":"jpg";
$sql="SELECT empr_foto2 FROM fotos_empreendimento WHERE empreendimentoID=$ID";
$result=mysql_query($sql) or die($sql.":".mysql_error());
$campos=mysql_fetch_assoc($result);
@unlink("../images/empr/".$campos["empr_foto2"]);
copy ($empr_foto2,"../images/empr/foto_empr_".$ID."_2.".$empr_foto2Extension);
unlink($empr_foto2);
$empr_foto2Name="empr_foto2='foto_empr_".$ID."_2.".$empr_foto2Extension."'";
} else {
if($del_empr_foto2=="on") {
$empr_foto2Name="empr_foto2=null";
$sql="SELECT empr_foto2 FROM fotos_empreendimento WHERE empreendimentoID=$ID";
$result=mysql_query($sql);
$campos=mysql_fetch_assoc($result);
@unlink("../images/empr/".$campos["empr_foto2"]);
//$key_foto2="key_foto2New=null";
} else {
$empr_foto2Name="";
//$key_foto2newl="";
}
}
$sql="UPDATE fotos_empreendimento SET $empr_foto2Name WHERE empreendimentoID=$ID";
$result=mysql_query($sql) or die("$sql:".mysql_error());
if($empr_foto3_name!="") {
$empr_foto3Extension=($empr_foto3_type=="image/gif")?"gif":"jpg";
$sql="SELECT empr_foto3 FROM fotos_empreendimento WHERE empreendimentoID=$ID";
$result=mysql_query($sql) or die($sql.":".mysql_error());
$campos=mysql_fetch_assoc($result);
@unlink("../images/empr/".$campos["empr_foto3"]);
copy ($empr_foto3,"../images/empr/foto_empr_".$ID."_3.".$empr_foto3Extension);
unlink($empr_foto3);
$empr_foto3Name="empr_foto3='foto_empr_".$ID."_3.".$empr_foto3Extension."'";
} else {
if($del_empr_foto3=="on") {
$empr_foto3Name="empr_foto3=null";
$sql="SELECT empr_foto3 FROM fotos_empreendimento WHERE empreendimentoID=$ID";
$result=mysql_query($sql);
$campos=mysql_fetch_assoc($result);
@unlink("../images/empr/".$campos["empr_foto3"]);
//$key_foto3="key_foto3New=null";
} else {
$empr_foto3Name="";
//$key_foto3New="";
}
}
$sql="UPDATE fotos_empreendimento SET $empr_foto3Name WHERE empreendimentoID=$ID";
$result=mysql_query($sql) or die("$sql:".mysql_error());
if($empr_foto4_name!="") {
$empr_foto4Extension=($empr_foto4_type=="image/gif")?"gif":"jpg";
$sql="SELECT empr_foto4 FROM fotos_empreendimento WHERE empreendimentoID=$ID";
$result=mysql_query($sql) or die($sql.":".mysql_error());
$campos=mysql_fetch_assoc($result);
@unlink("../images/empr/".$campos["empr_foto4"]);
copy ($empr_foto4,"../images/empr/foto_empr_".$ID."_4.".$empr_foto4Extension);
unlink($empr_foto4);
$empr_foto4Name="empr_foto4='foto_empr_".$ID."_4.".$empr_foto4Extension."'";
} else {
if($del_empr_foto4=="on") {
$empr_foto4Name="empr_foto4=null";
$sql="SELECT empr_foto4 FROM fotos_empreendimento WHERE empreendimentoID=$ID";
$result=mysql_query($sql);
$campos=mysql_fetch_assoc($result);
@unlink("../images/empr/".$campos["empr_foto4"]);
//$key_foto4="key_foto4New=null";
} else {
$empr_foto4Name="";
//$key_foto4newl="";
}
}
$sql="UPDATE fotos_empreendimento SET $empr_foto4Name WHERE empreendimentoID=$ID";
$result=mysql_query($sql) or die("$sql:".mysql_error());
if($empr_foto5_name!="") {
$empr_foto5Extension=($empr_foto5_type=="image/gif")?"gif":"jpg";
$sql="SELECT empr_foto5 FROM fotos_empreendimento WHERE empreendimentoID=$ID";
$result=mysql_query($sql) or die($sql.":".mysql_error());
$campos=mysql_fetch_assoc($result);
@unlink("../images/empr/".$campos["empr_foto5"]);
copy ($empr_foto5,"../images/empr/foto_empr_".$ID."_5.".$empr_foto5Extension);
unlink($empr_foto5);
$empr_foto5Name="empr_foto5='foto_empr_".$ID."_5.".$empr_foto5Extension."'";
} else {
if($del_empr_foto5=="on") {
$empr_foto5Name="empr_foto5=null";
$sql="SELECT empr_foto5 FROM fotos_empreendimento WHERE empreendimentoID=$ID";
$result=mysql_query($sql);
$campos=mysql_fetch_assoc($result);
@unlink("../images/empr/".$campos["empr_foto5"]);
//$key_foto5="key_foto5New=null";
} else {
$empr_foto5Name="";
//$key_foto5newl="";
}
}
$sql="UPDATE fotos_empreendimento SET $empr_foto5Name WHERE empreendimentoID=$ID";
$result=mysql_query($sql) or die("$sql:".mysql_error());
header("Location: empreendimentos.php");
exit;
}
?>
PART OF THE HTML
</head>
<body topmargin=0 leftmargin=0 bgcolor="#CCCC66">
<form name="empreendimentos" ENCTYPE="multipart/form-data" action="<?= $PHP_SELF ?>" method="post" onsubmit="return validate();">
<table cellpadding=0 cellspacing=0 border=0 class="bodyslhp" align="center" width=100%>
<tr>
<td width=10><img src="imgs/spacer.gif" width="5" height="1" alt="" border="0"></td>
<td width=10 nowrap valign=top></td>
<td></td>
<td width=10></td>
<td width=10 nowrap valign=top></td>
<td width=10></td>
</tr>
</table>
<br>
<table cellpadding=0 cellspacing=0 border=0 bgcolor="#055905" class="bodyslhp" align="center" width=100%>
<tr>
<td width=40><img src="imgs/spacer.gif" width="5" height="25" alt="" border="0"></td>
<td width=90 nowrap colspan="3">FOTOGRAFIAS </td>
</tr>
<tr>
<td width=40><img src="imgs/spacer.gif" width="5" height="1" alt="" border="0"></td>
<td width=10 nowrap><?= $empr_foto1 ?></td>
<td width=40 nowrap></td>
<td valign="bottom"><a class="bodyslhp">Foto 1: (100x75)<br></a> Seleccione esta caixa para apagar <input type="checkbox" name="del_empr_foto1" class="bodyslhp"><br> ou escolha uma nova imagem...<br><input type="file" class="bodys" name="empr_foto1" size="64"></td>
</tr>
</table>
<br>
<table cellpadding=0 cellspacing=0 border=0 class="bodyslhp" align="center" width=100%>
<tr>
<td width=10><img src="imgs/spacer.gif" width="5" height="1" alt="" border="0"></td>
<td width=10 nowrap valign=top></td>
<td></td>
<td width=10></td>
<td width=10 nowrap valign=top></td>
<td> PALAVRAS CHAVE: <br><textarea name="key_foto1New" cols=85 rows=1 class="textboxes"><?= $key_foto1 ?></textarea></td>
</tr>
</table>
<hr size="1" color="#CCCC66">
<br>
<table cellpadding=0 cellspacing=0 border=0 class="bodyslhp" align="center">
<tr><td><input type="submit" name="submit" value="Actualizar Empreendimento" class="button"></td></tr>
</table>
MORE TABLE HERE AND ...
</form>
</body>