Este es el código del procesador del form:
Código PHP:
include ("funciones.php");
include ("makethumb.txt");
# recogemos en una variable el nombre de BASE DE DATOS
$base="mi_base";
# recogemos en una variable el nombre de la TABLA
$tabla="mi_tabla";
# recoger y adaptar las variables pasadas desde el formulario
$jugador=$el_jugador;
$dbimage=$foto_actual;
$v1=$nombre;
$v2=$nac_fecha;
$v3=$pais;
$v4=$ciudad;
$v5=$e_civil;
$v6=$estudios;
$v7=$pasaporte;
$v8=$estatura;
$v9=$peso;
$v10=$image_function;
$v11=$userfile;
$v12=$tipo_jugador;
$v13=$prof_desde;
$v14=$categoria;
$v15=$puesto;
$v16=$vinculacion;
$v17=$libre;
$v18=$vctto_ano;
$v19=$partidos;
$v20=$caracteristicas;
# establecemos la conexion con el servidor
$conexion=mysql_connect("localhost","user","pass");
#asiganamos la conexión a una base de datos determinada
mysql_select_db($base,$conexion);
# MODIFICAMOS EL REGISTRO
mysql_query("UPDATE $tabla SET nombre_completo='$v1',fecha_nacimiento='$v2',Id_pais='$v3',ciudad='$v4',Id_ecivil='$v5',Id_estudios='$v6',pasaporte='$v7',estatura='$v8',peso='$v9',Id_tipo='$v12',profesional_desde='$v13',Id_categoria='$v14',Id_puesto='$v15',Id_vinculo='$v16',libre='$v17',vto_ctto='$v18',partidos_jugados='$v19',caracteristicas='$v20',ultima_actualizacion=NOW() WHERE (Id_jugador='$jugador')",$conexion);
#comprobamos el resultado de la insercion
# el error CERO significa NO ERROR
# el error 1062 significa Clave duplicada
if (mysql_errno($conexion)==0){echo "<p align='center'>Registro modificado exitosamente</p>";
}else{
if (mysql_errno($conexion)==1062){echo "<h2>No ha podido modificarse el registro<br>Ya existe un campo con este DNI</h2>";
}else{
$numerror=mysql_errno($conexion);
$descrerror=mysql_error($conexion);
echo "Se ha producido un error nº $numerror que corresponde a: $descrerror <br>";
}
}
# COMPROBAMOS LA IMAGEN
if ($image_function=="del"){
if ($dbimage !== "nofoto.jpg"){
// make sure image is not in use twice+
$image_dupe = mysql_query("select * from players_datos where foto='$dbimage'");
$image_total = mysql_num_rows($image_dupe);
if($image_total==1){
if (file_exists("/home/virtual/site142/fst/var/www/html/fotos/$dbimage")){
unlink("/home/virtual/site142/fst/var/www/html/fotos/$dbimage");
if (file_exists("/home/virtual/site142/fst/var/www/html/fotos/thumb_$dbimage")){
unlink("/home/virtual/site142/fst/var/www/html/fotos/thumb_$dbimage");}
}
// end if image total !==1
}
$dbimage = "nofoto.jpg";
$sql_update = "update players_datos set foto='$dbimage' where Id_jugador='$jugador'";
$result = mysql_query ($sql_update);}
}
// Upload
if ($image_function=="up"){
$path = "/home/virtual/site142/fst/var/www/html/fotos/";
$max_size = 512000;
if ($dbimage!=="nofoto.jpg")
{
$image_dupe = mysql_query("select * from players_datos where foto='$dbimage'");
$image_total = mysql_num_rows($image_dupe);
if($image_total==1){
if (file_exists("/home/virtual/site142/fst/var/www/html/fotos/$dbimage")){
unlink("/home/virtual/site142/fst/var/www/html/fotos/$dbimage");
if (file_exists("/home/virtual/site142/fst/var/www/html/fotos/thumb_$dbimage")){
unlink("/home/virtual/site142/fst/var/www/html/fotos/thumb_$dbimage");}
}
}// end if image total !==1
}
if (is_uploaded_file($userfile)) {
if ($userfile_size>$max_size) { echo "<p align=\"center\">Foto demasiado grande!</p>\n"; exit; }
if (($userfile_type=="image/x-png") || ($userfile_type=="image/pjpeg") || ($userfile_type=="image/jpeg")) {
if (file_exists("/home/virtual/site142/fst/var/www/html/fotos/$userfile_name")) { echo "<p align=\"center\">Una imagen con este nombre ya se encuentra en el servidor, por favor renombrela y vuelvala a subir!</p><br>\n";$escape=1; }
if($escape!=1){
$res = move_uploaded_file($userfile, $path . $userfile_name);
// create thumbnail
if (file_exists("/home/virtual/site142/fst/var/www/html/fotos/"."thumb_$userfile_name"))
{
unlink("/home/virtual/site142/fst/var/www/html/fotos/thumb_$userfile_name");
$thumb=new thumbnail("/home/virtual/site142/fst/var/www/html/fotos/$userfile_name");
$thumb->size_auto(75);
$thumb->jpeg_quality(75);
$thumb->save("/home/virtual/site142/fst/var/www/html/fotos/thumb_$userfile_name", $gd_version);
} else {
$thumb=new thumbnail("/home/virtual/site142/fst/var/www/html/fotos/$userfile_name");
$thumb->size_auto(75);
$thumb->jpeg_quality(75);
$thumb->save("/home/virtual/site142/fst/var/www/html/fotos/thumb_$userfile_name", $gd_version);
}
}
if($escape=1){$res="continue";}
// Resultant output
if (!$res) {
echo "<p align=\"center\">Fallo al subir imagen!<br><br><a href=\"javascript:history.back()\">Intentelo nuevamente</a></p>\n"; exit; }
} else { echo "<p align=\"center\">Extension de Archivo no permitida.<br><br><a href=\"javascript:history.back()\">Intentelo nuevamente</a></p>\n"; exit; }
if (empty($userfile_name))
{
$userfile_name="nofoto.jpg";
}
$sql_update = "update players_datos set foto='$userfile_name' where Id_jugador='$jugador'";
$result = mysql_query ($sql_update);
}
}
//$sql_select = "update players_datos set foto='$dbimage' where Id_jugador='$jugador'";
//$result = mysql_query($sql_select);
//while ($row = mysql_fetch_array($result))
//{
//$userfile_name = $row["foto"];
//}
# cerramos la conexion
mysql_close();
El problema ahora está en que cuando subo una nueva imagen o quiero borrar el registro en la BD de la existente, el script me sube la nueva imagen pero no me modifica el registro en la base de datos....
Estoy desorientado con esto...
Agradeceré sus respuestas, por favor... que no lo puedo terminar!!!!
Gracias... Totales
Saludos