codephp Posted August 25, 2013 Share Posted August 25, 2013 please check screen shot.... for error <div> <?php require_once("sendcontact.php"); $obj = new insertcontact(); $result = $obj->recordcontact(); ?> <?echo "<center>".$result."</center><br><br>"; ?> <form action="" method="post"> <table> <th><center> Please fill the form : </center></th> <tr> <td>Name :</td> <td><input type="text" name="fullname" placeholder="Type your full name"></td> </tr> <tr> <td>email :</td> <td><input type="email" name="email" placeholder="ex: [email protected]"></td> </tr> <tr> <td>Type of contact :</td> <td><input type="checkbox" name="checkbox" value="Report" >Report <br> <input type="checkbox" name="checkbox" value="Feedback" >Feedback <br> <input type="checkbox" name="checkbox" value="Suggestions" >Suggestions <br> </td> </tr> <tr> <td>Message:</td> <td><textarea name="message" style="max-width:500px;" cols="60" rows="10" placeholder="Type message here"></textarea></td> </tr> </table> <input type="submit"> </form> </div> contact.php <?php include('dbconnect.php'); class insertcontact{ public function recordcontact(){ // function for inserting videos $Name = $_POST["fullname"]; $email = $_POST["email"]; $message = $_POST["message"]; $type = $_POST["checkbox"]; $date = new DateTime(); $contactdate = $date-> format('Y-m-d H:i:s'); if(empty($Name) || empty($email) || empty($message) || empty($type)){ return $result = "Missing information....!"; }else{ $strSQL = " INSERT INTO Contact (Name, email, message, contact_type, date ) VALUES ('".$Name."','".$email."','".$message."','".$type."','".$contactdate."')" ; try{ mysql_query($strSQL); $message = "Thank you for submitting."; return $message ; clearstatcache(); exit(); } catch(CustomException $e){ throw new Exception( 'Something really gone wrong', 0, $e); exit(); } } } } ?> Link to comment https://forums.phpfreaks.com/topic/281539-need-help-with-my-code/ Share on other sites More sharing options...
codephp Posted August 25, 2013 Author Share Posted August 25, 2013 After checking preview my site, initially it showing that screen shot.... printing missing information .... may i know what's wrong. how do i validate required fields? Link to comment https://forums.phpfreaks.com/topic/281539-need-help-with-my-code/#findComment-1446653 Share on other sites More sharing options...
jazzman1 Posted August 25, 2013 Share Posted August 25, 2013 Make checkboxes to be optional. Link to comment https://forums.phpfreaks.com/topic/281539-need-help-with-my-code/#findComment-1446672 Share on other sites More sharing options...
PaulRyan Posted August 25, 2013 Share Posted August 25, 2013 You need to check if the form has been posted before you validate the information. <?PHP if($_SERVER['REQUEST_METHOD'] == 'POST') { // form has been posted } ?> Link to comment https://forums.phpfreaks.com/topic/281539-need-help-with-my-code/#findComment-1446685 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.