BasiM Posted October 17, 2013 Share Posted October 17, 2013 Hi. Hope someone can help. I have created a form that registers new users. It validates the information first before it inserts the data into the database. Problem : it does not validate the data meaning if u press submit it still processes the data. it does not insert the data into the database, it prints out error has occurred Please can some assist me. Thanx Here is the code <?php /* * author :basetsanamnl0@gmail.com * * * */ include 'connection.php'; $title=$_POST['title']; $surname=$_POST['surname']; $name=$_POST['name']; $id_number=$_POST['id_number']; $date_of_birth=$_POST['date_of_birth']; $gender=$_POST['gender']; $occupation=$_POST['occupation']; $mobile_number=$_POST['mobile_number']; $email_add=$_POST['email_add']; $postal_add=$_POST['postal_add']; $titleconfirm=""; $surnameconfirm=""; $nameconfirm=""; $id_numberconfirm=""; $date_of_birthconfirm=""; $genderconfirm=""; $occupationconfirm=""; $mobile_numberconfirm=""; $email_addconfirm=""; $postal_addconfirm=""; $message=""; if(isset($_POST['submit'])) { if(!$title){ $titleconfirm="please select title"; } if(!$surname){ $surnameconfirm="please enter surname "; } if(!$name){ $nameconfirm="please enter name"; } if(!$id_number){ $id_numberconfirm="please enter id number"; } if(!$date_of_birth){ $date_of_birthconfirm="please enter date of birth"; } if(!$gender){ $genderconfirm="Please select gender"; } if(!$occupation){ $occupationconfirm="please enter occupation"; } if(!$mobile_number){ $mobile_numberconfirm="please enter mobile name"; } if(!$email_add){ $email_addconfirm="please enter email address"; } if(!$postal_add){ $postal_addconfirm="please enter postal address"; } if($titleconfirm="please select title" && $surnameconfirm="please enter surname" && $nameconfirm="please enter name" && $id_numberconfirm="please enter id number" && $date_of_birthconfirm="please enter date of birth" && $genderconfirm="Please select gender" && $occupationconfirm="please enter occupation" && $mobile_numberconfirm="please enter mobile name" && $email_addconfirm="please enter email address" && $postal_addconfirm="please enter postal address") { $connection = new createConnection(); // creating connection $connect = $connection->connectToDatabase(); // connect to database $connection->selectDatabase(); // select database $surname = mysql_real_escape_string($_POST['surname']); $name =mysql_real_escape_string($_POST['name']); $id_number = mysql_real_escape_string($_POST['id_number']); $date_of_birth = mysql_real_escape_string($_POST['date_of_birth']); $gender = mysql_real_escape_string($_POST['gender']); $occupation = mysql_real_escape_string($_POST['occupation']); $mobile_number = mysql_real_escape_string($_POST['mobile_number']); $email_add = mysql_real_escape_string($_POST['email_add']); $postal_add = mysql_real_escape_string($_POST['postal_add']); //Insert into database $query = "INSERT INTO `patient`(title,surname,name,id_number,date_of_birth,gender,occupation,mobile_number,email_add,postal_add) VALUES ('title','$surname','$name','id_number','$date_of_birth','$gender','$occupation','$mobile_number','$email_add','$postal_add')"; if(mysql_query($query,$con)) { $message="<b style='color:lightgreen'>team selection inserted into database</b>"; $message= $message. "<br /><a href='paitent_info.html'>back to selection list</a>"; } else { die("error occured:". mysql_error());} } } if(isset($_POST['clear'])){ $title=""; $surname=""; $name=""; $id_number=""; $date_of_birth=""; $gender=""; $occupation=""; $mobile_number=""; $email_add=""; $postal_add=""; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/283063-user-registration/ Share on other sites More sharing options...
Ch0cu3r Posted October 17, 2013 Share Posted October 17, 2013 (edited) it does not insert the data into the database, it prints out error has occurred What is the error message? Also when you post code in the forum place paste it within tags Edited October 17, 2013 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/283063-user-registration/#findComment-1454327 Share on other sites More sharing options...
BasiM Posted October 17, 2013 Author Share Posted October 17, 2013 it prints out error occurred. Quote Link to comment https://forums.phpfreaks.com/topic/283063-user-registration/#findComment-1454345 Share on other sites More sharing options...
Ch0cu3r Posted October 17, 2013 Share Posted October 17, 2013 The error occurred message is coming from this line { die("error occured:". mysql_error());} This line is executed because mysql_query() returned false. When this happens it usually indicates there is an error with the query/mysql. The mysql_error() should display the actual error from MySQL. So is that the full complete error message you are getting? In order for use diagnose the problem you need to post the full complete error(s). Quote Link to comment https://forums.phpfreaks.com/topic/283063-user-registration/#findComment-1454347 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.