Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.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 允许将标点符号提交到MySQL数据库_Php_Mysql_Forms - Fatal编程技术网

Php 允许将标点符号提交到MySQL数据库

Php 允许将标点符号提交到MySQL数据库,php,mysql,forms,Php,Mysql,Forms,我已经设置好了所有的东西,这很有效,但是当我点击submit时,如果不出现MySQL语法错误,我就不能添加“或任何其他标点符号”。我想知道如何在表单的文本行中添加标点符号。我已经在排序规则下将其设置为utf8\uUnicode\uCI,但仍然出现语法错误 文本区是我希望能够提交任何标点符号或字符的地方。这是我的 这是我用的表格 print "<form method=post action=reply.php>"; print "<h3>Reply:</h3>

我已经设置好了所有的东西,这很有效,但是当我点击submit时,如果不出现MySQL语法错误,我就不能添加“或任何其他标点符号”。我想知道如何在表单的文本行中添加标点符号。我已经在排序规则下将其设置为utf8\uUnicode\uCI,但仍然出现语法错误

文本区是我希望能够提交任何标点符号或字符的地方。这是我的

这是我用的表格

print "<form method=post action=reply.php>";
print "<h3>Reply:</h3>";

print "<br><textarea name=reply_content textarea rows=4 cols=50></textarea>";
print "<input type=hidden name=reply_user value={$_SESSION['user_name']}>";
print "<input type=hidden name=topic_id value=$id>";
print "<br><input type=submit></form>";
print”“;
打印“回复:”;
打印“
”; 打印“”; 打印“”; 打印“
”;
这是reply.php的SQL语句

$reply_content=$_POST['reply_content'];
$reply_time=date('Y-m-d H:i:s');
$reply_user=$_POST['reply_user'];
$topic_id=$_POST['topic_id'];

mysql_query("INSERT INTO reply VALUES ('reply_id', '$reply_user', '$reply_content', '$reply_time', '$topic_id')") OR die(mysql_error());

print "<center><h1>Reply Posted Successfully</h1>";
$reply\u content=$\u POST['reply\u content'];
$reply_time=日期('Y-m-d H:i:s');
$reply\u user=$\u POST['reply\u user'];
$topic\u id=$\u POST['topic\u id'];
mysql_查询(“插入回复值('reply_id'、'reply_user'、'reply_content'、'reply_time'、'topic_id'))或死亡(mysql_error());
打印“回复投递成功”;
我知道有办法做到这一点,但我不知道怎么做。如果有人能帮我,我会非常感激的

尝试使用

$content=”“;
$content.=“回复:”;
$content.=“
”; $content.=”; $content.=”; $content.=“
”; $content=mysql\u real\u escape\u字符串($content);
您需要做很多事情,但要特别添加单引号等值,您需要做一些简单的事情,如:

$reply_content = mysql_real_escape_string($_POST['reply_content']);
这需要
$\u POST['reply\u content']
并在必要时添加反斜杠,以便将其插入MySQL。如果要向用户显示数据,请不要忘记将其反转。你不想让他们看到他们不希望看到的斜杠

另外,根据你的例子,你应该

  • 如果必须使用mysqli,请将所有mysqli函数替换为mysqli函数(mysqli函数不推荐用mysqli函数替换为mysqli函数)
  • 清理用户的任何输入-不要相信他们向您发送的内容。@MichaelBerkowski对“这是一个很好的开始”的评论是另一个
  • 试试这个(请参阅):

    print "<form method='post' action='reply.php'>";
    print "<h3>Reply:</h3>";
    
    print "<br><textarea name='reply_content' rows='4' cols='50'></textarea>";
    print "<input type='hidden' name='reply_user' value='{$_SESSION['user_name']}'>";
    print "<input type='hidden' name='topic_id' value='$id'>";
    print "<br><input type='submit'></form>";
    
    // Some PHP Stuff
    ?>
    <form method="post" action="reply.php">
    <h3>Reply:</h3>
    <textarea name="reply_content" rows="4" cols="50"></textarea><br/>
    <input type="hidden" name="topic_id" value="<?php echo $id; ?>" />
    <input type="submit" />
    </form>
    <?php
    // Go on with php stuff
    
    $reply\u content=mysql\u real\u escape\u字符串($\u POST['reply\u content'])

    另外,关于正确方法的一些提示:

    print "<form method='post' action='reply.php'>";
    print "<h3>Reply:</h3>";
    
    print "<br><textarea name='reply_content' rows='4' cols='50'></textarea>";
    print "<input type='hidden' name='reply_user' value='{$_SESSION['user_name']}'>";
    print "<input type='hidden' name='topic_id' value='$id'>";
    print "<br><input type='submit'></form>";
    
    // Some PHP Stuff
    ?>
    <form method="post" action="reply.php">
    <h3>Reply:</h3>
    <textarea name="reply_content" rows="4" cols="50"></textarea><br/>
    <input type="hidden" name="topic_id" value="<?php echo $id; ?>" />
    <input type="submit" />
    </form>
    <?php
    // Go on with php stuff
    
    您正在将会话中的用户名写入隐藏的输入字段。 试着这样做:

    session_start();
    $reply_user = $_SESSION['user_name'];
    
    您已在中添加了属性“textarea”:

    <textarea ... textarea>...
    
    。。。
    
    去掉这个

    像这样编辑HTML输出:

    print "<form method='post' action='reply.php'>";
    print "<h3>Reply:</h3>";
    
    print "<br><textarea name='reply_content' rows='4' cols='50'></textarea>";
    print "<input type='hidden' name='reply_user' value='{$_SESSION['user_name']}'>";
    print "<input type='hidden' name='topic_id' value='$id'>";
    print "<br><input type='submit'></form>";
    
    // Some PHP Stuff
    ?>
    <form method="post" action="reply.php">
    <h3>Reply:</h3>
    <textarea name="reply_content" rows="4" cols="50"></textarea><br/>
    <input type="hidden" name="topic_id" value="<?php echo $id; ?>" />
    <input type="submit" />
    </form>
    <?php
    // Go on with php stuff
    
    print”“;
    打印“回复:”;
    打印“
    ”; 打印“”; 打印“”; 打印“
    ”;
    或者像这样:

    print "<form method='post' action='reply.php'>";
    print "<h3>Reply:</h3>";
    
    print "<br><textarea name='reply_content' rows='4' cols='50'></textarea>";
    print "<input type='hidden' name='reply_user' value='{$_SESSION['user_name']}'>";
    print "<input type='hidden' name='topic_id' value='$id'>";
    print "<br><input type='submit'></form>";
    
    // Some PHP Stuff
    ?>
    <form method="post" action="reply.php">
    <h3>Reply:</h3>
    <textarea name="reply_content" rows="4" cols="50"></textarea><br/>
    <input type="hidden" name="topic_id" value="<?php echo $id; ?>" />
    <input type="submit" />
    </form>
    <?php
    // Go on with php stuff
    
    //一些PHP的东西
    ?>
    答复:
    

    这是一个常见且众所周知的问题。SQL语句需要转义一些字符才能有效,还需要防止严重的SQL注入漏洞(任何人都可能通过这些漏洞篡改您的数据库)。开始学习使用PDO,而不是使用
    mysql\u query()
    ,因为后者是一个旧的、现在已经弃用的API。不应使用
    mysql_*()
    函数编写新代码,因为您刚刚开始学习,这是一个正确学习的好时机。.本教程是一个很好的资源,它在旧
    mysql_*()
    函数的上下文中框架PDO和准备的语句。谢谢,但这不起作用。谢谢,它工作得很好。谢谢。当我运行这个程序时,我将切换到新语法并重做所有代码。这只是为了测试。但是,再次谢谢你!