Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.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插入表问题_Php_Mysql - Fatal编程技术网

PHP插入表问题

PHP插入表问题,php,mysql,Php,Mysql,又是我。我对PHP非常陌生,但我一直在努力练习,所以术语现在有点不确定 目前我的问题是我的CMS似乎无法将数据提交到MySQL表。以下是我的功能: function newEntry() { $query = mysql_query("INSERT INTO entries VALUES(null,'name','description','content')") or die(mysql_error()); } 这是我提交内容的表格: <form action="doN

又是我。我对PHP非常陌生,但我一直在努力练习,所以术语现在有点不确定

目前我的问题是我的CMS似乎无法将数据提交到MySQL表。以下是我的功能:

    function newEntry() {
    $query = mysql_query("INSERT INTO entries VALUES(null,'name','description','content')") or die(mysql_error());
}
这是我提交内容的表格:

<form action="doNewEntry.php" method="post">
    <textarea name="entTitle" id="entTitle">Entry Title</textarea><br>
    <textarea name="entDesc" id="entDesc">Input Description Here</textarea><br>
    <textarea name="entCont" id="entCont">Type and format content here! What you see, is what you get.</textarea><br>
    <script>
    CKEDITOR.replace( 'entCont' );
    </script>
    <table><td colspan="2"><input type="submit" name="submit" /></td></table>
</form>

参赛作品名称
在此处输入说明
在这里输入和格式化内容!所见即所得。
CKEDITOR.replace('entCont');
下面是发表文章的中间文件:

    <?php
include('includes/functions.php');
if(isset($_POST['submit'])) {
            if(isset($_POST['entTitle'])) {
                newEntry($_POST['entTitle'],$_POST['entDesc'],$_POST['entCont']);
                header("Location: entries.php");
        } else {
            echo "Please fill out all fields!";
            include('newEntry.php');
    }
}
?>


我对这一点非常陌生,所以这无疑是一个非常简单的解决方案。也许只是错过了一些东西,但我真的无法理解。添加问题:(

您需要在函数中传递变量,以便向函数中添加参数,否则它将不起作用,并且您的变量应在查询中以
$
开头,因此请按如下所示更改函数

function newEntry($name, $description, $content) 
{
    $query = mysql_query("INSERT INTO entries VALUES(null,'$name','$description','$content')") or die(mysql_error());
}

作为旁注,我想说的是,您的代码非常容易受到攻击。我宁愿切换到或,并使用准备好的语句来避免任何风险。

您已将参数传递给newEntry调用,但在newEntry函数中未获得任何参数!这些值是静态的,他需要使用传递给函数的参数(例如:$title、$desc、$content)。此函数位于管理面板中,因此它不会受到没有密码的人的威胁。我认为这不对吗?我想如果此系统有用,我会在以后了解PDO。我现在还收到一个错误:列计数与行的值计数不匹配1@jack我宁愿指示查询中的所有秆,以便
插入到表中(第1列、第2列等)值(“值1”、“值2”等)
function newEntry($name, $description, $content) 
{
    $query = mysql_query("INSERT INTO entries VALUES(null,'$name','$description','$content')") or die(mysql_error());
}