vaxzz vaxzz - 1 month ago 6
PHP Question

PHP - INSERT Query failing, returns no error. Beginner

<form action="" method="post">
<input type="text" id="title" name="title" />
<input type="text" id="link" name="link" />
<input type="submit" value="Add resource" />
<?php
if(isset($_POST['title']) && $_POST['link']) {
$t = $_POST['title'];
$l = $_POST['link'];

$con = mysqli_connect("localhost","root","","rman");

if (mysqli_connect_errno()) {
die("Failed to connect to MySQL:" . mysqli_connect_error());
}

mysqli_query($con, "INSERT INTO tutorials (id, title, link, section) VALUES ('','$t','$l','')");
}
?>
</form>


How can this not work? I have removed every single part that might have caused this. Nothing is going in the database, no errors returning whatsoever.

For everyone wondering:
DB name: rman
Table name: tutorials
colums: id (INT11, Auto increment), title (Text), link (Text), section(INT11)

Am I being blind here? I'm sorry if thats the situation. Hope someone can see what I am doing wrong and help me out.

Answer

use mysqli_error() to check error code, as well as don't insert blank id if it;s AI ;)

cheers