Home  >  Article  >  Backend Development  >  Why is the w3schools SQL Insertion Tutorial Causing an Error in Line 13?

Why is the w3schools SQL Insertion Tutorial Causing an Error in Line 13?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-10-21 07:45:03496browse

Why is the w3schools SQL Insertion Tutorial Causing an Error in Line 13?

SQL Insertion Error in w3schools Tutorial

Attempting to follow a w3schools tutorial, numerous users have encountered errors when using their provided code example. The error typically manifests in line 13, which begins with mysqli_query.

Analysis of the code reveals a critical error in the mysqli_query function call. According to MySQL's documentation, the first parameter of mysqli_query must be a connection string. However, the code provided by w3schools fails to establish a connection.

To resolve this error, programmers must make the following modification:

$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);");

Additionally, it is advisable to enclose column names in backticks, as some column names used in the code are reserved words. This modification will ensure successful data insertion into the MySQL database.

The above is the detailed content of Why is the w3schools SQL Insertion Tutorial Causing an Error in Line 13?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn