Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- hello guys i've been battling with this no show my data can't get into the database it just prints the else part of my function
- karose-services_db.php
- error_reporting( E_ALL & ~E_DEPRECATED & ~E_NOTICE );
- $servername = "localhost";
- $username = "root";
- $password = "";
- $db= "karose-services_db";
- register.php
- <?php
- /**
- * Created by IntelliJ IDEA.
- * User: Karachi
- * Date: 10/29/2017
- * Time: 7:14 AM
- */
- require_once 'karose-services_db.php';
- error_reporting(E_ALL); ini_set('display_errors', 1);
- session_start();
- if(isset($_SESSION['user_id'])) {
- header("Location: index.php");
- }
- /**
- * validate form
- * @return boolean return true if no error found, otherwise return false
- */
- $errors= array();
- $firstname='';
- $lastname='';
- $email='';
- $mobile='';
- $c_name='';
- $s_experience='';
- $t_size='';
- $m_turnover='';
- $a_details='';
- $services='';
- $o_services='';
- $city='';
- $o_city='';
- $s_location='' ;
- function validate_form(){
- global $firstname,$lastname,$email,$mobile,$c_name, $s_experience, $t_size,$m_turnover,
- $a_details,$services,$o_services,$city,$o_city,$s_location,$errors ;
- if(isset($_POST['txtfirstname'])!=''){
- $firstname= filter_var($_POST['txtfirstname'], FILTER_SANITIZE_STRING);
- if ($firstname==''){
- $errors[]="hey! name is required";
- }
- }else{
- $errors[]="you must enter your name";
- }
- if(isset($_POST['txtlastname'])!=''){
- $lastname= filter_var($_POST['txtlastname'], FILTER_SANITIZE_STRING);
- if ($lastname==''){
- $errors[]="hey! name is required";
- }
- }else{
- $errors[]="you must enter your name";
- }
- if(isset($_POST['txtemail']) !=''){
- $email= filter_var($_POST['txtemail'], FILTER_SANITIZE_STRING);
- if( !filter_var($email, FILTER_VALIDATE_EMAIL)){
- $errors[]='email is not valid';
- }
- }else{
- $errors[]='please email is required';
- }
- if(isset($_POST['txtmobile'])!=''){
- $mobile= filter_var($_POST['txtmobile'],FILTER_SANITIZE_NUMBER_INT);
- if($mobile==''){
- $errors[]='please enter your number';
- }
- }else{
- $errors[]='enter valid number';
- }
- if(isset($_POST['txtcompany'])!=''){
- $c_name= $_POST['txtcompany'];
- }else{
- $errors[]='please enter company name';
- }
- if(isset($_POST['selexperience' ])!=''){
- $s_experience=$_POST['selexperience'];
- }else{
- $errors[]= ' please select one';
- }
- if(isset($_POST['selteamsize'])!=''){
- $t_size= $_POST['selteamsize'];
- }else{
- $errors[]=' please select one';
- }
- if(isset($_POST['selmon_turnover'])!=''){
- $m_turnover=$_POST['selmon_turnover'];
- }else{
- $errors[]='please select one ';
- }
- if(isset($_POST['additional_details'])!=''){
- $a_details= filter_var($_POST['additional_details'], FILTER_SANITIZE_STRING);
- if($a_details==''){
- $errors[]='please enter valid information or contact us ';
- }
- }
- if(isset($_POST['selservices[]'])){
- $services=$_POST['selservices[]'];
- }
- if(isset($_POST['txtotherservice']) !=''){
- $o_services=filter_var($_POST['txtotherservice'], FILTER_SANITIZE_STRING);
- if($o_services== $services){
- $errors[]='please enter valid information';
- }else{
- $errors[]='please enter valid information or contact us ';
- }
- }
- if(isset($_POST['selcity[]']) !=''){
- $city= $_POST['selcity[]'];
- if($city==''){
- $errors[]='enter something valid';
- }
- }
- if(isset($_POST['txtothercity']) !=''){
- $o_city= filter_var($_POST['txtothercity'], FILTER_SANITIZE_STRING);
- if($o_city==''){
- $errors[]='check what you entered';
- }
- }
- if(isset($_POST['txtotherlocation'])!=''){
- $s_location= filter_var($_POST['txtotherlocation'],FILTER_SANITIZE_STRING );
- if ($s_location){
- $errors[]='please enter something right';
- }
- }
- if(count($errors)){
- return false;
- }else{
- return true;
- }
- }
- var_dump(validate_form());
- //function display_value($fieldName){
- // echo isset($_POST[$fieldName]) ? $_POST[$fieldName] : '';
- //}
- function insert_user($firstname,$lastname,$email,$mobile,$c_name, $s_experience, $t_size,$m_turnover,
- $a_details,$services,$o_services,$city,$o_city,$s_location){
- global $dbh, $msg;
- echo "here{$GLOBALS['dbh']}";
- // construct SQL insert statement
- $sql_insert = "INSERT INTO partners(firstname, lastname, mail, mobilenumber, companyname,experience, teamsize, monthlyturnover,qualifications,servicesprovided, anotherservice, city, anothercity, specificareas)
- VALUES(" . $dbh->quote($firstname) .", " . $dbh->quote( $lastname) . ", " . $dbh->quote($email) . ", " . $dbh->quote($mobile) . ", " . $dbh->quote($c_name) . ", " . $dbh->quote($s_experience) . ", " . $dbh->quote($t_size) . ", " . $dbh->quote($m_turnover) . ", " . $dbh->quote($a_details) . ", " . $dbh->quote($services) . ",
- " . $dbh->quote($o_services) . ", " . $dbh->quote($city) . ", " . $dbh->quote($o_city) . ", " . $dbh->quote($s_location) . ")";
- if($dbh->exec($sql_insert) === false){
- $msg = 'Error inserting the partner.';
- return false;
- }else{
- $msg = "The new partner is created";
- return true;
- }
- }
- function start_form(){
- // if user submitted the form
- if(isset($_POST['btncreatepartner']))
- {
- // validate form
- if(validate_form())
- {
- require_once 'karose-services_db.php';
- $dsn = "mysql:host=$servername;dbname=$db";
- try {
- // create database connection
- new PDO($dsn, $username, $password);
- insert_user(firstname, lastname, mail, mobilenumber, companyname,experience, teamsize, monthlyturnover,qualifications,servicesprovided, anotherservice, city, anothercity, specificareas);
- } catch (PDOException $e) {
- echo $e->getMessage();
- }
- }
- }else{
- echo 'error ';
- }
- }
- start_form();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement