Click here to Skip to main content
15,886,551 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Im trying to insert data from web-page to database with input tags,i didnt get anything in my database and the connection file is doing good,what do you think about this take a look to my code(if there another way to do it share with me)

<html>
        <head></head>
        <body>


        <!--2017-12-22 21:52:50-->
        <form method="post" action="">
      <input type="text" placeholder='ID' name='id'> <p> 
      <input type="text" placeholder='NOM' name='nom'> <p> 
      <input type="text" placeholder='PRENOM' name='prenom'> <p>
        <input type="submit" value="INSERT INTO" name='but1'>
            </form>

        <?php
        include("connection.php");

        $id = $_POST['id'];
        $nom = $_POST['nom'];
        $prenom = $_POST['prenom'];
    if(isset($_POST['but1']))
{
        $query = "INSERT INTO student VALUES($id,$nom,$prenom,CURRENT_TIMESTAMP)";
    mysqli_query($con , $query);}


    //    $query = "insert into student values(12,'nom1','prenom2',CURRENT_TIMESTAMP)";




        ?>

    </body>
    </html>


What I have tried:

nothing yet
nothing yet
nothing yet
Posted
Updated 25-Dec-17 17:29pm

1 solution

The query should be
$query = "INSERT INTO student VALUES('$id','$nom','$prenom',CURRENT_TIMESTAMP)";
like this and you should consider to assign $_POST['values'] after checking isset condition as below,

if(isset($_POST['but1'])){
         $id = $_POST['id'];
         $nom = $_POST['nom'];
         $prenom = $_POST['prenom'];
         $query = "INSERT INTO student VALUES('$id','$nom','$prenom',CURRENT_TIMESTAMP)";
     }

This will omit the error
Notice: Undefined index: id in .....


and consider about CURRENT_TIMESTAMP return value.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900