Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert row into MySQL database with MySQLi

Tags:

php

mysql

mysqli

Can someone spot the mistake:

mysqli_query($connection, "INSERT INTO comments (event_id, fulltext, date_posted) VALUES (5, 'Hallo', 430234)");

The connection is established, but it just doesn't insert a new row.

include("../../connect.php");

$event_id = intval($_GET["event_id"]);
$fulltext = $_GET["fulltext"];
$date = intval($_GET["date"]);

mysqli_query($connection, "INSERT INTO comments ('event_id', 'fulltext', 'date_posted') VALUES (5, 'Hallo', 430234)");

echo "INSERT INTO comments (event_id, fulltext, date_posted) VALUES (5, 'Hallo', 430234)";

mysqli_close($connection);
like image 332
user1734282 Avatar asked Apr 04 '13 06:04

user1734282


People also ask

How do I add a new row in MySQL?

When inserting a single row into the MySQL table, the syntax is as follows: INSERT INTO table_name(column_1,column_2,column_3) VALUES (value_1,value_2,value_3); In the INSERT INTO query, you should specify the following information: table_name : A MySQL table to which you want to add a new row.

How can I insert multiple rows in HTML table in MySQL using PHP?

Inserting Multiple Rows into a Table. One can also insert multiple rows into a table with a single insert query at once. To do this, include multiple lists of column values within the INSERT INTO statement, where column values for each row must be enclosed within parentheses and separated by a comma.

Can we use MySQL and MySQLi together?

Using the PHP MySQL to MySQLi Migration PackagePHP MySQL to MySQLi is package that emulates the mysql extension functions using the mysqli extension. It uses these replacement code solutions and can act as a stop-gap while you work on migrating your code.

How do I insert a row into a database?

To insert a row into a table, you need to specify three things: First, the table, which you want to insert a new row, in the INSERT INTO clause. Second, a comma-separated list of columns in the table surrounded by parentheses. Third, a comma-separated list of values surrounded by parentheses in the VALUES clause.


1 Answers

FULLTEXT is reserved word in mysql you can't use it as column name use below query with ` around column name

mysqli_query($connection, "INSERT INTO comments 
(`event_id`, `fulltext`, `date_posted`) VALUES (5, 'Hallo', 430234)");
like image 167
Yogesh Suthar Avatar answered Oct 27 '22 15:10

Yogesh Suthar