为什么PHP向我展示这个未定义的函数

为什么PHP向我展示这个未定义的函数,php,Php,你好,我只是想创建一个博客,我偶然发现了这个问题 致命错误:在第5行的D:\xampp\htdocs\wd1\u vtec\u 0100348514\pages\post\u add.php中调用未定义的函数mysql\u safe\u query() 这是我在特定页面上的代码 <?php // post_add.php if(!empty($_POST)) { include 'config.php'; if(mysql_safe_query('INSERT INTO p

你好,我只是想创建一个博客,我偶然发现了这个问题

致命错误:在第5行的D:\xampp\htdocs\wd1\u vtec\u 0100348514\pages\post\u add.php中调用未定义的函数mysql\u safe\u query()

这是我在特定页面上的代码

<?php
// post_add.php
if(!empty($_POST)) {
    include 'config.php';
    if(mysql_safe_query('INSERT INTO posts (title,body,date) VALUES (%s,%s,%s)', $_POST['title'], $_POST['body'], time()))
        echo 'Entry posted. <a href="post_view.php?id='.mysql_insert_id().'">View</a>';
    else
        echo mysql_error();
}
?>

<?php
include 'header.php';
?>

<form method="post">
    <table>
        <tr>
            <td><label for="title">Title</label></td>
            <td><input name="title" id="title" /></td>
        </tr>
        <tr>
            <td><label for="body">Body</label></td>
            <td><textarea name="body" id="body"></textarea></td>
        </tr>
        <tr>
            <td></td>
            <td><input type="submit" value="Post" /></td>
        </tr>
    </table>
</form>

 <link rel="stylesheet" type="text/css" href="../css/style1.css">



        <div id="menu">
    <ul id="nav">
        <li><a href="home.php" target="_self" >Home</a></li>
        <li><a href="session1.php" target="_self" >Sessions</a>
            <ul>
                <li><a href="session1.php" target="_self" >Session 1</a></li>
                <li><a href="session2.php" target="_self" >Session 2</a></li>
                <li><a href="session3.php" target="_self" >Session 3</a></li>
                <li><a href="session4.php" target="_self" >Session 4</a></li>
                <li><a href="session5.php" target="_self" >Session 5</a></li>
                <li><a href="session6.php" target="_self" >Session 6</a></li>
                <li><a href="session7.php" target="_self" >Session 7</a></li>
                <li><a href="session8.php" target="_self" >Session 8</a></li>
                <li><a href="session9.php" target="_self" >Session 9</a></li>
                <li><a href="session10.php" target="_self" >Session 10</a></li>
                <li><a href="session11.php" target="_self" >Session 11</a></li>
                <li><a href="session12.php" target="_self" >Session 12</a></li>
                <li><a href="session13.php" target="_self" >Session 13</a></li>
                <li><a href="session14.php" target="_self" >Session 14</a></li>



            </ul>

            <li><a href="blog.php" target="_self" >Blog</a></li>




    </ul>
    <div style="float:right">  <a class="btn btn-danger logout" href="logout.php" > Logout</a> </div>
    </div>







<?php include ('footer.php'); ?> 

标题
身体
我已经尝试过各种方法来解决这个问题,但我不确定如何继续下去。任何帮助都将不胜感激


谢谢

这是因为您没有定义方法
mysql\u safe\u query()
。它不包含在PHP中。将以下方法添加到
config.php

function mysqli_safe_string($value) {
    if(empty($value))           return 'NULL';
    elseif(is_string($value))   return '\''.mysqli_real_escape_string(trim($value)).'\'';
    elseif(is_numeric($value))  return $value;
    elseif(is_array($value))    return implode(',',array_map('mysqli_safe_string',$value));
    else                        return false;
}

function mysqli_safe_query($format) {
    $args = array_slice(func_get_args(),1);
    $args = array_map('mysql_safe_string',$args);
    $query = vsprintf($format,$args);
    return mysqli_query($query);
}
资料来源:(我在谷歌上搜索到的第一个链接)


请注意,我将所有内容都更改为
mysqli\uuu
,而不是
mysql\uu
mysql已经有一段时间被弃用了,我真的不知道为什么这里提问的人仍然使用它。将所有的
mysql\u
方法更改为
mysqli\u
,包括用于DB连接配置文件的方法。

您认为该方法是在哪里定义的?它似乎不是一个核心功能。你从哪里得到这些代码的?按一下这是一个函数:?@Darren和我在Google上找到的其他人;-)这里有一个等等,这没关系。他们会继续使用它们,而你会提供一个解决方案,比如你在上面发布的复制粘贴。@Darren Sally极有可能是she。该函数不起作用,因为它包含
mysqli\uu
函数-你需要修改它,使其与OP当前的代码一起工作,因为OP使用的是
mysql\uquot/code>@willsignal哈哈,我甚至没有注意到这一点。给你10个布朗尼点数;-)@Darren另一方面,如果OP是Salvador,我可能在sh|t名单上。:)