Hola que tal, bueno estoy realizando una validacion con sessio_start(), mi formulario funciona muy bien!. El problema es: cuando quiero enviar los datos a la DB_ no me da ningun problema, pero cuando yo reviso la DB_ no aparece ningun dato. que puedo hacer al respecto! aca dejo el codigo! Y muchas gracias.
=form.php
<?
// inicia php session_satar();
session_start();
// errores de la session.
$error = $_SESSION[ 'error' ];
// Confirmacion de formulario
$msg = $_SESSION[ 'msg' ];
?>
<?
if ( strlen( trim( $error ) ) > 0 ) {
?>
<br><br>Favor arreglar los sigueintes errores:<br>
<?= $error ?>
<br><br>
<?
}// if
if ( strlen( trim( $msg ) ) > 0 ) {
?>
<br><br><?= $msg ?><br><br>
<?
}// if
?>
<form name="form" id="form" action="process.php">
<ul>nombre:<input type="text" name="nombre" value="<?= $_SESSION['nombre'] ?>"></ul>
<ul>e-mail:<input type="text" name="mail" value="<?= $_SESSION['mail'] ?>"></ul>
<ul>Telefono:<input type="text" name="tel" value="<?= $_SESSION['tel']?>"></ul>
<ul>Comentario:<textarea rows="5" cols="25" name="cmsg" value="<?= $_SESSION['cmsg']?>"></textarea></ul>
<ul><input type="submit" value="Enviar"><input type="reset" value="Limpiar"></ul>
</form>
<?
// limpiar info de mensaje
unset ( $_SESSION['msg'] );
//limpiar mensaje de error
unset ( $_SESSION['error']);
?>
=process.php
<?
// start PHP session
session_start();
// clear confirmation message
unset( $_SESSION[ 'msg' ] );
// clear error message
unset( $_SESSION[ 'error' ] );
$error = "";
//nombre
$nombre = $_REQUEST[ 'nombre' ];
if ( strlen( trim( $nombre ) ) < 1 ) {
$error .= "<li>Se requiere un nombre</li>";
}// if
$_SESSION[ 'nombre' ] = trim( $nombre );
//mail
$mail = $_REQUEST[ 'mail' ];
if ( strlen( trim( $mail ) ) < 1 ) {
$error .= "<li>Se requiere un e-mail</li>";
}// if
$_SESSION[ 'mail' ] = trim( $mail );
//tel
$tel = $_REQUEST[ 'tel' ];
if ( strlen( trim( is_numeric ($tel) ) ) < 1 ) {
$error .= "<li>Se requiere un Telefono o Valor numerico</li>";
}// if
$_SESSION[ 'tel' ] = trim( $tel );
//msg
$cmsg = $_REQUEST['cmsg'];
if (strlen(trim( $cmsg )) < 1){
$error .="<li>Se requiere un mensaje</li>";
}//if
$_SESSION['cmsg'] = trim ( strip_tags( $cmsg ));
//prosesando formulario y buscando errores si hay errores haga esto! sino ->
if ( strlen( trim( $error ) ) > 0 ) {
// set errorMsg in session
$_SESSION[ 'error' ] = $error;
} else {
// set confirmation message
$_SESSION[ 'msg' ] = "Gracias,<br> " ." $nombre<br> ". "$mail<br> " . "$tel<br>" ." $cmsg<br> ". ", Tu informacion fue enviada correctamente";
// clear form values and error message
unset( $_SESSION[ 'nombre' ] );
unset( $_SESSION[ 'mail' ] );
unset( $_SESSION[ 'tel' ] );
unset($_SESSION[ 'cmsg' ]);
}// if-else
// redireccionar y revisar si los datos estan llenos!...
//funcion para mysql_conection;
if($_SESSION['nombre'] . $_SESSION['tel'] . $_SESSION['mail'] . $_SESSION['cmsg'] ==true){
//coneccion a la BD_ mysql.
function crearConeccion (){
$USUARIO = "root";
$HOSTNAME = "localhost";
$PWD = "3333";
$DB_NAME = "db_once";
$coneccion = mysql_connect ( $USUARIO, $HOSTNAME, $PWD);
if( $coneccion ){
mysql_select_db ( $coneccion, $DB_NAME) or die ('No se puede conectar a la DB_');
return $coneccion;
}else {
echo "No se puede seleccionar<BR>" . $DB_NAME;
}//if-else
}//function crearConeccion
//solicitando datos para la DB_
if( $_SESSION['nombre'] . $_SESSION['mail'] . $_SESSION['tel'] . $_SESSION['cmsg'] == true){
$coneccion = crearConeccion();
//introducir en la DB_
if ($coneccion){
$sql = "insert into db_once (nombre, mail, tel, cmsg) values ('". $_SESSION['nombre'] ."','". $_SESSION['mail'] ."','". $_SESSION['tel'] ."','". $_SESSION['cmsg'] ."')";
$suceso = mysql_query ( $coneccion, $sql);
if (!$suceso){echo "Error con sql" . $sql;}
}//if coneccion
}//if
}//if msg = true all function
header( "Location: form.php" );
?>