Blue Blue - 6 months ago 11x
PHP Question

Inserting data to table (mysqli insert)

I've been looking at this code for a while now and I can't see where the problem is. I have been reading the whole of StackOverflow and still can't see where my error is.


mysql_select_db("web_table") or die(mysql_error());

if (mysqli_connect_errno()) {

echo "Failed to connect to MySQL: " . mysqli_connect_error();

echo "<p> Connection Successful!"

mysqli_query('INSERT INTO web_formitem (ID, formID, caption, key, sortorder, type, enabled, mandatory, data) VALUES (105, 7, Tip izdelka (6), producttype_6, 42, 5, 1, 0, 0)');

echo "<p>Insert successfull";


The error is somewhere in line 13, thats
. I tried to help myself with but it's not helping me much.


Warning: Never ever refer to w3schools for learning purposes. They have so many mistakes in their tutorials.

According to the mysqli_query documentation, the first parameter must be a connection string:

$link = mysqli_connect("localhost","root","","web_table");

mysqli_query($link,"INSERT INTO web_formitem (`ID`, `formID`, `caption`, `key`, `sortorder`, `type`, `enabled`, `mandatory`, `data`)
VALUES (105, 7, 'Tip izdelka (6)', 'producttype_6', 42, 5, 1, 0, 0)") 
or die(mysqli_error($link));

Note: Add backticks ` for column names in your insert query as some of your column names are reserved words.