Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在sql表问题中输入变量_Php_Sql - Fatal编程技术网

Php 在sql表问题中输入变量

Php 在sql表问题中输入变量,php,sql,Php,Sql,好的,我在将变量插入sql表时遇到问题。这是我的密码 if (isset ($_GET['comment'])) $commentEntered = $_GET['comment']; else $commentEntered = "refuse"; 上面我得到了变量 然后我尝试用下面的代码将其传递到数据库 $sql = "insert into $DB_Table (comment) values('$commentEntered');"; $res = mysql_que

好的,我在将变量插入sql表时遇到问题。这是我的密码

if (isset ($_GET['comment']))
    $commentEntered = $_GET['comment'];
else
    $commentEntered = "refuse"; 
上面我得到了变量 然后我尝试用下面的代码将其传递到数据库

$sql = "insert into $DB_Table (comment) values('$commentEntered');";
$res = mysql_query($sql,$con) or die(mysql_error());

mysql_close($con);
if ($res) {
    echo "success";
}else{
    echo "faild";
}// end else
我的问题是,当我传递一个单词时,它可以工作,但是当收到评论的文本框中有空格时,它不会插入

i、 e-用户输入Hello-这有效

用户进入Hello World-这不起作用

任何帮助都将不胜感激

试试看

$sql = "INSERT INTO " . $table . " (comment) " . 
       "VALUES ('" . mysql_real_espace_string($commentEntered) . "')";
另外,转储在“$sql=…”行之前输入的var$comments,以查看它输出到屏幕的内容

var_dump($commentEntered);
还有一件事,试着从GET-request方法切换到POST并从$\u-POST获取数据。

试着调用:

 mysql_query("COMMIT");

在关闭连接之前。

sql注入攻击警告,以及评论的字段类型是什么?当你看到他时请代我问候……我不太担心,因为它只能通过个人iPhone应用程序访问,从中传递的字段类型只是一个普通的文本字段mysql db field type.oh只是一个可以容纳100个字符的varchar字段
mysql\u real\u espace\u string()
?这就是你开始清理数据库的时候了吗?@DaveRandom你是什么意思?好吧,上次我查看时,函数名为
mysql\u real\u escape\u string()
…转储$sql变量,你看到了什么?如果我回显iPhone应用程序中输入的$commentented,它只会在包含一个单词时返回变量。为什么整个句子都不读?