PHP button to insert data into MYSQL

Button for insert operation is not working

code: html

 <form method= "post " action="">  
   Experiment name : <input type="text" name="exp_name" placeholder="Enter exp Name" Required>
  Exp Date : <input type="text" name="exp_date" placeholder="Enter date" Required>
  sbst name : <input type="text" name="sb_name" placeholder="Enter sb name" Required>
  sbst id : <input type="text" name="sb_id" placeholder="Enter sb id" Required>
   Exp TIME : <input type="text" name="exp_time" placeholder="Enter time" Required>
   machine : <input type="text" name="machine_name" placeholder="Enter mach name" Required>
   incharge : <input type="text" name="exp_incharge" placeholder="Enter incharge" Required>
   team : <input type="text" name="exp_team" placeholder="Enter team" Required>
  <input type="submit" name="submit" value="Submit">


    include 'db_con.php';
    $conn = OpenCon(); // establish connection
    echo "Connected Successfully";
        $Exp_name = $_POST['exp_name'];
        $Exp_date = $_POST['exp_date']; 
        $Subset_name = $_POST['sb_name'];
        $Subset_id = $_POST['sb_id'];
        $Exp_time = $_POST['exp_time'];
        $machine = $_POST['machine_name'];
        $Exp_Incharge = $_POST['exp_incharge'];
        $Exp_team = $_POST['exp_team'];
        $sql = "INSERT INTO pre_exp_details (
'$Exp_name ',
            if(mysqli_query($conn, $sql)){
                echo "Records inserted successfully.";
            } else{
                echo "ERROR: Could not able to execute $sql. ". mysqli_error($conn);


Not working HOW?

What is the error being given?

1 Like

Your form’s method=’…’ attribute value has extra spaces in it and is not valid. When you submitted the form, you should have seen the URL in the browser’s address bar change to include all the key/value pair data from the form as get data, the default when there is no valid method attribute.

1 Like

Also, sometimes you need to add a pound sign in your action. I had to do this on one server. For some reason it would not work with a null value. Doubt this is stopping yours from working, but, maybe…
< form action="#" method=“post”>

1 Like

When submitting to the same page just leave the action attribute out completely.

1 Like

Thank you all . The issue was as phdr said , there was extra space in method attribute.

Sponsor our Newsletter | Privacy Policy | Terms of Service