Hola a todos, estoy haciendo un formulario con upload de imagen que se registra a una base de datos pero tengo un error de sintaxis que dice "unexpected end of file" en la ultima linea (donde esta el "?>") y nose donde esté el problema. Espero me puedan dar sugerencias, ejemplos o decirme cual es el error, gracias de antemano. ::)
El error esta en esta imagen:
http://img717.imageshack.us/img717/2692/erroryl.jpg (http://img717.imageshack.us/img717/2692/erroryl.jpg)
Y este es el codigo:
<?php
if (isset($_POST['enviar']))
{
$link = mysql_connect('localhost', 'user', 'pass');
mysql_select_db('dbname', $link);
$sql = "SELECT MAX(ID) FROM inscripciones";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
$max_id = $row[0]+1;
$nombres=$_POST['nombres'];
$apellidos=$_POST['apellidos'];
$DNI_CarneExtranjeria=$_POST['DNI_CarneExtranjeria'];
$tipo_persona=$_POST['tipo_persona'];
$empresa=$_POST['empresa'];
$cargo=$_POST['cargo'];
$direccion=$_POST['direccion'];
$telefono_fijo=$_POST['telefono_fijo'];
$telefono_celular=$_POST['telefono_celular'];
$tipo_combrobante=$_POST['tipo_comprobante'];
$razon_social=$_POST['razon_social'];
$RUC=$_POST['RUC'];
$_FILES['voucher']['name'] = $max_id."_".$_FILES['voucher']['name'];
$upload_dir = '/home/netline/public_html/inscripciones/vouchers/';
$extension = $_FILES['voucher']['type'];
$size = $_FILES['voucher']['size'];
$upload_file = $upload_dir.($_FILES['voucher']['name']);
$voucher_nombre_db = $_FILES['voucher']['name'];
if($nombres.trim == '' && $apellidos.trim == '' && $DNI_CarneExtranjeria.trim == '' && ($tipo_persona == 'Dependiente' && ($empresa.trim == '' || $cargo.trim == '' || $direccion.trim == '')) &&($telefono_fijo == '' || $telefono_celular == '') && ($tipo_comprobante == 'Factura' && ($razon_social.trim == '' || $RUC.trim == '')) && $voucher_nombre_db.trim == '' && $extension != 'image/jpeg' && $size > 204801)
{
echo <<<ERROR
<html>
<head>
<title>Titulo web</title>
<META http-equiv="refresh" content="6; url=http://www.dominio.com/inscripciones/inscripcion.php">
</head>
<body>
<p>Debe completar todos los datos obligatorios y adjuntar una imagen con extensi�n .JPG y de 200KB de tamaño maximo.</p>
</body>
</html>
ERROR;
}
else
{
move_uploaded_file($_FILES[voucher][tmp_name], "$upload_file");
mysql_query("INSERT INTO inscripciones (Nombres,Apellidos,DNI_CarneExtranjeria,Tipo_Persona,Empresa,Cargo,Direccion,Telefono_Fijo,Telefono_Celular,Tipo_Comprobante,Razon_Social,RUC,Nombre_Voucher) VALUES ('$nombres','$apellidos','$DNI_CarneExtranjeria','$tipo_persona','$empresa','$cargo','$direccion','$telefono_fijo','$telefono_celular','$tipo_comprobante','$razon_social','$RUC','$voucher_nombre_db')",$link);
mysql_close($link);
echo <<<EXITO
<html>
<head>
<title>Titulo web</title>
<META http-equiv="refresh" content="6; url=http://www.dominio.com/inscripciones/inscripcion.php">
</head>
<body>
<p>Registro exitoso.</p>
</body>
</html>
EXITO;
}
}
?>
Intenta organizar el código de tal manera que puedas identificar más fácil el error.
<?php
if (isset($_POST['enviar'])){
$link = mysql_connect('localhost', 'user', 'pass');
mysql_select_db('dbname', $link);
$sql = "SELECT MAX(ID) FROM inscripciones";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
$max_id = $row[0]+1;
$nombres=$_POST['nombres'];
$apellidos=$_POST['apellidos'];
$DNI_CarneExtranjeria=$_POST['DNI_CarneExtranjeria'];
$tipo_persona=$_POST['tipo_persona'];
$empresa=$_POST['empresa'];
$cargo=$_POST['cargo'];
$direccion=$_POST['direccion'];
$telefono_fijo=$_POST['telefono_fijo'];
$telefono_celular=$_POST['telefono_celular'];
$tipo_combrobante=$_POST['tipo_comprobante'];
$razon_social=$_POST['razon_social'];
$RUC=$_POST['RUC'];
$_FILES['voucher']['name'] = $max_id."_".$_FILES['voucher']['name'];
$upload_dir = '/home/netline/public_html/inscripciones/vouchers/';
$extension = $_FILES['voucher']['type'];
$size = $_FILES['voucher']['size'];
$upload_file = $upload_dir.($_FILES['voucher']['name']);
$voucher_nombre_db = $_FILES['voucher']['name'];
if($nombres.trim == '' && $apellidos.trim == '' && $DNI_CarneExtranjeria.trim == '' && ($tipo_persona == 'Dependiente' && ($empresa.trim == '' || $cargo.trim == '' || $direccion.trim == '')) &&($telefono_fijo == '' || $telefono_celular == '') && ($tipo_comprobante == 'Factura' && ($razon_social.trim == '' || $RUC.trim == '')) && $voucher_nombre_db.trim == '' && $extension != 'image/jpeg' && $size > 204801){
echo '<html>
<head>
<title>Titulo web</title>
<META http-equiv="refresh" content="6; url=http://www.dominio.com/inscripciones/inscripcion.php">
</head>
<body>
<p>Debe completar todos los datos obligatorios y adjuntar una imagen con extensi�n .JPG y de 200KB de tamaño maximo.</p>
</body>
</html>';
}else{
move_uploaded_file($_FILES[voucher][tmp_name], "$upload_file");
mysql_query("INSERT INTO inscripciones(Nombres,Apellidos,DNI_CarneExtranjeria,Tipo_Persona,Empresa,Cargo,Direccion,Telefono_Fijo,Telefono_Celular,Tipo_Comprobante,Razon_Social,RUC,Nombre_Voucher) VALUES('$nombres','$apellidos','$DNI_CarneExtranjeria','$tipo_persona','$empresa','$cargo','$direccion','$telefono_fijo','$telefono_celular','$tipo_comprobante','$razon_social','$RUC','$voucher_nombre_db')",$link);
mysql_close($link);
echo '<html>
<head>
<title>Titulo web</title>
<META http-equiv="refresh" content="6; url=http://www.dominio.com/inscripciones/inscripcion.php">
</head>
<body>
<p>Registro exitoso.</p>
</body>
</html>';
}
}
?>
Hola, gracias por corregir el error, tienes razon... debo ser mas ordenado ;D un saludo.