将数据插入表(mysqli插入) [英] Inserting data to table (mysqli insert)

查看:52
本文介绍了将数据插入表(mysqli插入)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看了一段时间了,我看不出问题出在哪里.我一直在阅读整个StackOverflow,但仍然看不到我的错误在哪里.

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.

<?php

mysqli_connect("localhost","root","","web_table");
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";

?>

错误在第13行中,即mysqli_query('insert....我试图通过 http://www.w3schools.com/php/php_mysql_insert.asp 来帮助自己a>但这对我没有太大帮助.

The error is somewhere in line 13, thats mysqli_query('insert.... I tried to help myself with http://www.w3schools.com/php/php_mysql_insert.asp but it's not helping me much.

推荐答案

警告:切勿出于学习目的而引用 w3schools .他们在教程中有很多错误.

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

根据 mysqli_query 文档,第一个参数必须是连接字符串:

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.

这篇关于将数据插入表(mysqli插入)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆