php - Why query not inserting record -


i trying insert simple 2 values in db neither inserting nor giving errors. not know what's happening. tried sql query outside if statement did not work.

please help

coding file

<?php       include 'includes/db_connection.php';       if (isset($_post['submit']))      {        $name = test_input($_post["name"]);        $fathername = test_input($_post["fathername"]);       $sql = "insert student (name,fathername)     values ('$name','$fathername')";     mysqli_query($conn, $sql);      if(mysqli_query($conn, $sql))     {         $last_id = mysqli_insert_id($conn);         echo "new record created successfully. last inserted id is: " . $last_id;     }     else      {         echo "error: " . $sql . "<br>" . mysqli_error($conn);     }      function test_input($data) {        $data = trim($data);        $data = stripslashes($data);        $data = htmlspecialchars($data);        return $data;     }      }       ?>       <!doctype html>     <!--     change license header, choose license headers in project properties.     change template file, choose tools | templates     , open template in editor.     -->     <html>         <head>             <meta charset="utf-8">             <title></title>      <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>     <script src="//cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.2.43/jquery.form-validator.min.js"></script>         </head>            <body>              <form action="valid_test.php" method="post" id="registration-form">             <div>         name         <input name="name" data-validation="length alphanumeric"               data-validation-length="6-15"               data-validation-error-msg="user name has alphanumeric value (6-15 chars)">         </div>          <div>         father name         <input name="fathername" data-validation="length alphanumeric"               data-validation-length="6-20"               data-validation-error-msg="user name has alphanumeric value (6-20 chars)">         </div>            <div>         <input type="submit" value="validate">         <input type="reset" value="reset form">       </div>     </form> 

when post html form, elements posted name attribute.

you missing name attribute submit button.

change:

<input type="submit" value="validate"> 

to:

<input type="submit" value="validate" name="submit"> 

as submit button not have name attribute, condition

if (isset($_post['submit'])) not getting fulfilled , hence code not working.

also, repeating mysqli_query($conn, $sql);. remove first instance of it.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -