3

好的,我的发布脚本有点问题。一切都很好,除了当我输入一个像撇号一样的短语时,例如“这是我的标题”不会​​发布,而“这是我的标题”会发布。不知道为什么会这样。也许我真的不知道条形标签,我该怎么办?当它不起作用时,我会收到底部错误消息

} else {
if(isset($_POST['what'])&&isset($_POST['when'])&&isset($_POST['where'])&&isset($_POST['details'])&&isset($_POST['sponsored_by'])&&isset($_POST['collegeId'])){

$what = nl2br(htmlspecialchars(strip_tags(stripslashes(trim($_POST['what'])))));

$where = nl2br(htmlspecialchars(strip_tags(stripslashes(trim($_POST['where'])))));

$when = nl2br(htmlspecialchars(strip_tags(stripslashes(trim($_POST['when'])))));

$sponsored_by = nl2br(htmlspecialchars(strip_tags(stripslashes(trim($_POST['sponsored_by'])))));

$details = nl2br(htmlspecialchars(strip_tags(stripslashes(trim($_POST['details'])))));
    $collegeId = intval($_POST["collegeId"]);
    if(isset($_SESSION['username'])){

$username = htmlspecialchars(strip_tags(stripslashes(trim(($_SESSION['username'])))));
        $query = "select id, Name from users where username='$username' and activated = 1";
        $doQuery = mysql_query($query);
        if(mysql_num_rows($doQuery)>0){
            $results = mysql_fetch_array($doQuery);
            $userName = $results['Name'];
            $email = $username;
            $id = $results['id'];
            $query = "insert into events values(NULL,$id,$collegeId,'$what','$when','$where','$details','$sponsored_by',NOW())";
            if(mysql_query($query)) header("Location: collegeInfo.php?college=$collegeId&message=added");
            else echo "Failed to create new Event!".$query;
4

1 回答 1

6

你不要逃避你的查询。尝试至少使用addslashes或清理您的输入mysql_real_escape_string。所以stripslashes- 从行中删除反斜杠。用于addslashes添加它们,而不是在 mysql 查询之前删除。

老兄,在新的 php 版本中mysql_query弃用,请使用带有准备好的语句的 PDO。

于 2012-09-12T01:14:54.810 回答