【发布时间】:2013-03-16 14:14:09
【问题描述】:
我正在尝试使用以下 PHP 代码向 MySQL 表添加信息。 (从 HTML5 基本 Web 表单中输入名称和文本。)可能是语法问题?
<?php
include "dbinfo.php"; //contains mysqli_connect information (the $mysqli variable)
//inputs
$name = $_GET["name"];
$text = $_GET["text"];
$sqlqr = 'INSERT INTO `ncool`.`coolbits_table` (`name`, `text`, `date`) VALUES ("$name", "$text", CURRENT_TIMESTAMP);'; //the query. I'm pretty sure that the problem is a syntax one, and is here somewhere.
mysqli_query($mysqli,$sqlqr); //function where the magic happens.
?>
没有抛出错误。结果是一个空白屏幕,并且将带有“$name”和“$text”的行添加到 MySQL 表中。
【问题讨论】:
-
警告!您的代码很容易受到 SQL 注入攻击。阅读有关如何转义 SQL 变量的信息,最好使用准备好的语句。
-
根据发布的代码,插入的行和空白屏幕正是我所期望的。
-
mysqli_error() 返回什么?
-
@EdGibbs 是的,但是添加的是变量名(字面意思是 $name),而不是它的值。
-
@Jocelyn mysqli_error() 不返回任何内容(假设我使用正确)。
标签: php mysql phpmyadmin mysqli