0

My mysqli insert doesn't work for some reason but I don't get any errors.

<?php

$con = mysqli_connect("localhost", "root", "", "dice");
if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

mysqli_query($con, "INSERT INTO `gamble` (thr,score,tstamp)
    VALUES ('test123','test123','test123')");
echo "New record has id: " . mysqli_insert_id($con);

mysqli_close($con);

I really don't know what I did wrong.

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • 2
    The script doesn't test for errors automatically, and you don't test for errors either (at least not when executing the insert statement). Check the result of `mysqli_query` and call `mysqli_error` to get more detailed error information. – GolezTrol May 28 '16 at 22:51
  • `tstamp` sounds to be something like a timestamp. Writing a string to it most likely will break the stuff. What are the datatypes of the columns in `kgp`? – EagleRainbow May 28 '16 at 22:53
  • 1
    suggestion for improving the error handling: `mysqli_query($con,"INSERT INTO gamble (thr,score,tstamp) VALUES ('test123','test123','test123')") or die (mysqli_error($con));` – EagleRainbow May 28 '16 at 22:56

0 Answers0