johnake Posted May 29, 2008 Share Posted May 29, 2008 Hello, I don't know if this is the right place to post, but I have a problem with my script. So here it goes. I have a contact page wich requeires some fields to be completed. The problem is when i type in the browser ?action=validate it inserts in the db a blank email adress and sends the mail with blank fields. The code loooks like this: <?php require_once('libs/Smarty.class.php'); require_once('lib/config.php'); $smarty = new Smarty(); require_once('leftColumn.php'); require_once('rightColumn.php'); //We declare the sessions if(!isset($_SESSION['nume'])) $_SESSION['nume'] = ''; if(!isset($_SESSION['email'])) $_SESSION['email'] = ''; if(!isset($_SESSION['subiect'])) $_SESSION['subiect'] = ''; if(!isset($_SESSION['mesaj'])) $_SESSION['mesaj'] = ''; if(!isset($_GET['actiune'])) $_GET['actiune'] = ''; switch($_GET['action']){ case '': $smarty->assign('titlu_formular', 'Formular de contact'); $campuri = array('nume' => array('camp' => 'Nume', 'valoare' => $_SESSION['nume']), 'email' => array('camp' => 'E-mail', 'valoare' => $_SESSION['email']), 'subiect' => array('camp' => 'Subiect', 'valoare' => $_SESSION['subiect'])); $textarea = array('mesaj' => array('camp' => 'Mesaj', 'valoare' => $_SESSION['mesaj'])); $smarty->assign('textarea', $textarea); $smarty->assign('formular', $campuri); break; case 'validate': $_SESSION['nume'] = $_POST['nume']; $_SESSION['email'] = $_POST['email']; $_SESSION['subiect'] = $_POST['subiect']; $_SESSION['mesaj'] = $_POST['mesaj']; $smarty->assign('done', 'Mesajul a fost trimis cu succes!'); $sql_insert_mail = "INSERT INTO `adrese` (`email`) VALUES ('".addentities($_SESSION['email'])."')"; mysql_query($sql_insert_mail)or die('Nu am putut adauga adresa in baza de date!'); $catre = '[email protected]'; $data_trimitere = date('d-m-Y H:i:s'); $subiect = $_SESSION['subiect']; $mesaj = ' <html> <head> <title>Formular de contact</title> </head> <body> <p><tt>Data trimitere: '.$data_trimitere.'</tt></p> <table> <tr> <td><tt>Nume: '.$_SESSION['nume'].'</tt></td> </tr> <td><tt>E-mail: '.$_SESSION['email'].'</tt></td> </tr> <tr> <td><tt>Subiect: '.$_SESSION['subiect'].'</tt></td> </tr> <tr> <td><tt>Mesaj:<br><br>'.$_SESSION['mesaj'].'</tt></td> </tr> </table> </body> </html>'; $headere = "MIME-Version: 1.0\r\n"; $headere .= "Content-type: text/html; charset=iso-8859-1\r\n"; $headere .= "From: ".$_SESSION['email']."\r\n"; mail($catre, $subiect, $mesaj, $headere); $_SESSION['nume'] = ''; $_SESSION['email'] = ''; $_SESSION['subiect'] = ''; $_SESSION['mesaj'] = ''; break; } $smarty->display('contact.tpl'); ?> Quick mention: I made an if statement that checks if the session is blank but it seems to skip that declaration. . I don't need a rewrite of the script just an explanation where I did wrong. Thank you Link to comment https://forums.phpfreaks.com/topic/107771-switch-case-problem/ Share on other sites More sharing options...
thebadbad Posted May 29, 2008 Share Posted May 29, 2008 My guess is that the $_POST array is empty? You didn't say anything about submitting a form. Link to comment https://forums.phpfreaks.com/topic/107771-switch-case-problem/#findComment-552421 Share on other sites More sharing options...
defeated Posted May 29, 2008 Share Posted May 29, 2008 I don't know if this will help at all..... I'm a noobie, but try removing $_SESSION['nume'] = ''; $_SESSION['email'] = ''; $_SESSION['subiect'] = ''; $_SESSION['mesaj'] = ''; from the end of your case. I think it sets email, suiect, and mesaj to be blank. apologies if I have it all wrong. Link to comment https://forums.phpfreaks.com/topic/107771-switch-case-problem/#findComment-552429 Share on other sites More sharing options...
johnake Posted May 29, 2008 Author Share Posted May 29, 2008 The script uses Smarty Web Templates engine. The $_POSTS are empty... I made something like this, but I have no ideea where to put this to in the code. if ($_POST['nume']==''||$_POST['email']==''||$_POST['subiect']==''||$_POST['mesaj']==''{ print("Display some error here!"); } Link to comment https://forums.phpfreaks.com/topic/107771-switch-case-problem/#findComment-552431 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.