Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.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 Can';t从$\u POST input将数组变量插入MySQL数据库_Php_Mysql_Arrays_Post_Insert - Fatal编程技术网

Php Can';t从$\u POST input将数组变量插入MySQL数据库

Php Can';t从$\u POST input将数组变量插入MySQL数据库,php,mysql,arrays,post,insert,Php,Mysql,Arrays,Post,Insert,和往常一样,我试图根据已经存在的问题来研究和解决这个问题,但我不能对它掉以轻心。我可能做了很多错事。在html表单中,我有输入类型text、number、title以及textarea,所以这可能也解释了一些不起作用的原因 以下是我试图构建的东西的链接: 这是我的插入查询函数 function register_hangout($register_hangout_data) { array_walk($register_hangout_data, 'array_sanitize'

和往常一样,我试图根据已经存在的问题来研究和解决这个问题,但我不能对它掉以轻心。我可能做了很多错事。在html表单中,我有输入类型text、number、title以及textarea,所以这可能也解释了一些不起作用的原因

以下是我试图构建的东西的链接:

这是我的插入查询函数

    function register_hangout($register_hangout_data) {
    array_walk($register_hangout_data, 'array_sanitize');

    $hangout_fields = '`' . implode('`, `', array_keys($register_hangout_data)) . '`';
    $hangout_data = '\'' . implode('\', \'', $register_hangout_data) . '\'';

    mysql_query("INSERT INTO hangouts ($hangout_fields) VALUES ($hangout_data)");
}
下面是代码,到目前为止,它确实将我重定向到hangout.php?success,但不回显“successsss”或插入数据库:

    if (empty($_POST) === false) {
    $required_fields = array('title','dd' ,'mm','yyyy', 'hour', 'minutes', 'location', 'aim', 'description');
    foreach($_POST AS $key=>$value) {
        if (empty($value) && in_array($key, $required_fields) === true) {
            $errors[] = 'Fields marked with an asterisk are required.';
            break 1;
        }
    }  

    print_r($errors);
}

?> 

<?php 
if (isset($_GET['success']) && empty($_GET['success'])) {
    echo 'Successssssss.';
} else {
  // there's one curly brace after the html form tied to this else right above
    if (empty($_POST) === false && empty($errors) === true) {
        //insert hangout data in mysql database
        $register_hangout_data = array(
            'title'             => $_POST['title'],
            'dd'                => $_POST['dd'],
            'mm'                => $_POST['mm'],
            'yyyy'              => $_POST['yyyy'],
            'hour'              => $_POST['hour'],
            'minutes'           => $_POST['minutes'],
            'location'          => $_POST['location'],
            'aim'               => $_POST['aim'],
            'description'       => $_POST['description']
            );
        register_hangout($register_hangout_data);
        header('Location: hangout.php?success');
        // exit
    }
    elseif (empty($errors) === false) {
        //output errors
        echo output_errors($errors);
    }
if(空($\u POST)==false){
$required_fields=数组('title','dd','mm','yyyy','hour','minutes','location','aim','description');
foreach($\发布为$key=>$value){
if(空($value)&&in_数组($key,$required_字段)==true){
$errors[]='需要标有星号的字段';
破口1;
}
}  
打印错误($errors);
}
?> 

你们为什么一直使用不推荐的mysql?我几乎在每个问题上都能看到它。正如@Inurosen所提到的。你还应该看看Hi Inurosen。我已经自学了很多东西,我还是一个初学者,不懂很多东西。所以我跟随一些在线教程学习登录和注册系统,因为这家伙是一个非常好的老师,只是碰巧视频是旧的,2012年。我只是从那里开始推断代码。不推荐使用,不推荐使用,我现在希望了解编程逻辑,并且能够使事情正常运行,我不会在现实世界的应用程序中使用它。希望这对更高级的程序员来说是有意义的,他们会原谅我。另外,我是一个处女,PHP是我的第一个,我们只是在第二垒。你用哪个MySQL API连接,
MySQL
<代码>mysqli
?PDO?其他的?您也没有在此处检查错误。