Explore Courses Blog Tutorials Interview Questions
0 votes
in SQL by (6.1k points)

I am having this following code, I am getting an error and I can't see where the problem 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";


I think the error is somewhere in line 13, that's mysqli_query('insert...

Can anyone help with this?

1 Answer

0 votes
by (12.7k points)

Here, the first parameter should 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 the column names in your insert query because some of your column names are the reserved words.

Want to be a SQL expert? Register for out SQL Training by Intellipaat to learn more.

Related questions

0 votes
1 answer
asked Jan 8, 2021 in SQL by Appu (6.1k points)
0 votes
1 answer
asked Jan 3, 2021 in SQL by Appu (6.1k points)
0 votes
1 answer
asked Dec 22, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories