Luuk Wuijster Luuk Wuijster - 28 days ago 20
MySQL Question

$query = INSERT INTO doesn't work

For some reason INSERT INTO doesn't insert.
I've watched Youtube video's, googled a lot and I just can figure it out.
So, What am I doing wrong? because it just works in other projects...

$link = mysqli_connect("localhost", "root", "Password", "news");

if(mysqli_connect_error()){

die("Database fout " . mysqli_connect_error());

}

if (isset($_POST['submit'])){

$query = "INSERT INTO `Artiekel` (`titel`, `auteur`, `inhoud`, `datum`)
VALUES('"
. mysqli_real_escape_string($link, $_POST['titel']) . "', '"
. mysqli_real_escape_string($link, $_POST['auteur']) . "','"
. mysqli_real_escape_string($link, $_POST['inhoud']) . "','"
. date("d/m/Y") . "')";

}


FYI, I tested the $_POST's and they are not empty.

I really hope someone can help me out :)

Thanks in advance,

Luuk

Answer

You should execute the query

  if (isset($_POST['submit'])){

    $query = "INSERT INTO `Artiekel` (`titel`, `auteur`, `inhoud`, `datum`) 
        VALUES('"
        . mysqli_real_escape_string($link, $_POST['titel'])  . "', '"
        . mysqli_real_escape_string($link, $_POST['auteur']) . "','"
        . mysqli_real_escape_string($link, $_POST['inhoud']) . "','"
        . date("d/m/Y") . "')";

    mysqli_query($link ,$query );  //  execute the query

  }