Link to home
Start Free TrialLog in
Avatar of iman suhan
iman suhan

asked on

i am unable to add data to mysql database

$firstname = $_POST['firstname'];
      echo 'Your firstname is ' .$firstname. '<br>';
      
      $secondname = $_POST['secondname'];
      echo 'Your secondname is ' .$secondname. '<br>';
      
      $location = $_POST['location'];
      echo 'Your location is ' .$location. '<br>';
      
      $designation = $_POST['designation'];
      echo 'Your designation is ' .$designation. '<br>';
      
      $fileno = $_POST['fileno'];
      echo 'Your fileno is ' .$fileno. '<br>';
   
      // date to display
    $rawdate = htmlentities($_POST['doa']);
    $doa = date('Y-m-d', strtotime($rawdate));
      echo 'Your dateofapplication is ' .$doa. '<br>';
   
    $rawdate = htmlentities($_POST['doj']);
    $doj = date('Y-m-d', strtotime($rawdate));
      echo 'Your dateofjoining is ' .$doj. '<br>';
   
      $door1 = $_POST['door1'];
      echo ' dooraccess is available for ' .$door1. '<br>';
      
      $door2 = $_POST['door2'];
      echo 'dooraccess is available for  ' .$door2. '<br>';

      $door3 = $_POST['door3'];
      echo 'dooraccess is available for  ' .$door3. '<br>';

    $door4 = $_POST['door4'];
      echo 'dooraccess is available for  ' .$door4. '<br>';
      
      $door5 = $_POST['door5'];
      echo 'dooraccess is available for  ' .$door5. '<br>';
      
      $door6 = $_POST['door6'];
      echo 'dooraccess is available for  ' .$door6. '<br>';
      
      $door7 = $_POST['door7'];
      echo 'dooraccess is available for  ' .$door7. '<br>';
      
      $door8 = $_POST['door8'];
      echo 'dooraccess is available for  ' .$door8. '<br>';
      
      $door9 = $_POST['door9'];
      echo 'dooraccess is available for  ' .$door9. '<br>';
      
      $door10 = $_POST['door10'];
      echo 'dooraccess is available for  ' .$door10. '<br>';
      
      $door11 = $_POST['door11'];
      echo 'dooraccess is available for  ' .$door11. '<br>';
      
      $door12 = $_POST['door12'];
      echo 'dooraccess is available for  ' .$door12. '<br>';
      
      // commments to display       
   //$comments = $_POST['comments'];
   //echo 'Your comments is ' .$comments. '<br>';
                    
      // Getting the form variable fileno and then placing their values into the MySQL table
      //$fileno = $_POST['fileno'];
      //echo 'Your fileno is ' .$fileno. '<br>';
   
      // date to display
    //$rawdate = htmlentities($_POST['date']);
    //$date = date('Y-m-d', strtotime($rawdate));
      //echo 'Your comments is ' .$date. '<br>';
   
   //email to display
     //$email = $_POST['email'];
     //echo 'Your email is ' .$email. '<br>';
      
      
      
      
      

//if (!empty($_POST['firstname']) && !empty($_POST['secondname'])&& !empty($_POST['location'])&& !empty($_POST['designation']) && !empty($_POST['fileno']) && !empty($_POST['card1'])  && !empty($_POST['card2']) && !empty($_POST['cardgrrd'])&& !empty($_POST['door1']) && !empty($_POST['door2']) && !empty($_POST['door3']) && !empty($_POST['door4']) && !empty($_POST['door5']) && !empty($_POST['door6']) && !empty($_POST['door7']) && !empty($_POST['door8']) && !empty($_POST['door8']) && !empty($_POST['door9']) && !empty($_POST['door10']) && !empty($_POST['door11']) && !empty($_POST['door12']) && !empty($_POST['door13']) )
if(isset($_POST['submit']))
{
 
    $query = "INSERT INTO form_details1(firstname,secondname,location,designation,fileno,doa,doj,cardtype1,cardcolor,cardtype2,door1,door2,door3,door4,door5,door6,door7,door8,door9,door10,door11,door12,door13) VALUES('$firstname','$secondname','$location','$designation','$fileno','$doa','$doj','$cardtype1',$cardcolor,'$cardtype2','$door1','$door2','$door3','$door4','$door5','$door6','$door7','$door8','$door9','$door10','$door11','$door12')"; //query
    if(mysqli_query($connect,$query)){ //check query executed or not
        echo 'inserted' . '<br>' ;
            
    }else{
        echo "problem occur".mysqli_error($connect);
            
    }
}else{
   echo "form values are required";
}database.docx
database.docx
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Please use the code snippet feature when you post code here at E-E, thanks.  You can click the word "CODE" in the comment formatting bar and paste your code in between the tags.  This gives us line numbers and a unispace font making it easier to read and discuss the code.
Suggest you simplify the problem and reduce it to something we can all work with.  Please, please, please post your test data!  Then when we have the simplified version working, we can build back up from there to the full application.

SSCCE

Getting Started
Avatar of John Tsioumpris
Have your run the SQL Insert query with some static data to check if it works as it should....
ASKER CERTIFIED SOLUTION
Avatar of arnold
arnold
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
mysqli_real_escape_string() requires the link identifier (connection id) as the first argument, and the input variable as the second argument.
http://php.net/manual/en/mysqli.real-escape-string.php
Avatar of iman suhan
iman suhan

ASKER

thanks