Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.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
$\u POST中的Php动态变量不会命中_Php_Html_Forms_Dynamic_Xhtml - Fatal编程技术网

$\u POST中的Php动态变量不会命中

$\u POST中的Php动态变量不会命中,php,html,forms,dynamic,xhtml,Php,Html,Forms,Dynamic,Xhtml,我准备把头发扯下来 基本上,我必须创建一个页面,读取文件目录并创建一个表单,允许您按每个文件名旁边的导入按钮将文件导入数据库 我像这样扫描目录: $files=scandir('uploads');//get array of files/directories in uploads foreach($files as $file) {//loop through the array if(!is_dir($file)) {//if not a directory must be a f

我准备把头发扯下来

基本上,我必须创建一个页面,读取文件目录并创建一个表单,允许您按每个文件名旁边的导入按钮将文件导入数据库

我像这样扫描目录:

$files=scandir('uploads');//get array of files/directories in uploads
foreach($files as $file) {//loop through the array
    if(!is_dir($file)) {//if not a directory must be a file
        echo $file.'<input type="submit" value="Import CSV File" name="'.$file.'" >';
    }
}
正如我单击按钮导入文件时的评论所示,
if(isset($\u POST[$file])
从不点击

我不知道为什么

为了更好地全面理解,页面上还有一些代码

导入_csv.php:

<?php 
    if(session_id()=='') {
        session_start(); 
    }
    // check if user is not logged in thus is most likely not allowed to view the page or login went wrong
    if(!isset($_SESSION['loggedin'])||$_SESSION['loggedin']===false) {
        echo '<p>You are not logged in. Please <a href="index.php">login</a> and try again.</p>';
        exit();//stops the execution of the php file so we dont show the links below to unauthorized visitors
    }

    $files=scandir('uploads');//get array of files/directories in uploads
    foreach($files as $file) {//loop through the array
        if(!is_dir($file)) {//if not a directory must be a file
            if(isset($_POST[$file])) {
                echo 'aa';
                exit();
            }
        }
    }
?>

<h2 align="center">Import CSV Files:</h2>

<p align="center">
This will allow you to view names of uploaded CSV files and import them into the database.
Below are a list of available files on the server to be imported:
</p>

<form method="post" action="import_csv.php">

<?php

    //Create connection and suppress any errors for now using @
    $con=@mysqli_connect('localhost','jd','1111','my_db');

    // Check connection
    if (mysqli_connect_errno($con)) {
        echo 'Could not connect to database.';
        exit();
    }else {
        //query all tables in db
        $sql = "SHOW TABLES FROM my_db;";
        $result = mysqli_query($con,$sql);


        //loop through results/all tables
        while ($row = mysqli_fetch_row($result)) {
            if($row[0]=='users'&&isset($_SESSION['user_type']) && $_SESSION['user_type']!='admin') {
            }else {
                echo '<input type="checkbox" name="'.$row[0].'" > '.$row[0].'<br></br>';
            }
        }
    }

    $files=scandir('uploads');//get array of files/directories in uploads
    foreach($files as $file) {//loop through the array
        if(!is_dir($file)) {//if not a directory must be a file
            echo $file.'<input type="submit" value="Import CSV File" name="'.$file.'" >';
        }
    }
?>
</form>

导入CSV文件:

这将允许您查看上载的CSV文件的名称并将其导入数据库。 以下是服务器上要导入的可用文件列表:


这是因为文件扩展名问题,文件扩展名始终应为“.”,但php将其转换为“\u1”。那么请重写你的代码,就像

$files=scandir('uploads');//get array of files/directories in uploads
foreach($files as $file) {//loop through the array
    $postName   =   str_replace('.','_',$file);
        if(isset($_POST[$postName])) {//if not a directory must be a file
            echo 'aa';
            exit();
        }
    }

在这里,$文件应该像file.csv一样,但PHP请求数组包含$\u POST[file\u csv]

这是因为文件扩展名问题,文件扩展名始终应该是“.”,但PHP请求数组将其转换为“\p>”。那么请重写你的代码,就像

$files=scandir('uploads');//get array of files/directories in uploads
foreach($files as $file) {//loop through the array
    $postName   =   str_replace('.','_',$file);
        if(isset($_POST[$postName])) {//if not a directory must be a file
            echo 'aa';
            exit();
        }
    }

在这里,$文件应该像file.csv一样,但是PHP请求数组包含$\u POST[file\u csv]

文件名是$\u POST数组中的一个键?从哪里寄来的?@Dagon你什么意思?表单标记中是我的php块,它通过扫描目录创建按钮和按钮旁边的文本。当按下按钮时,表单将post导入同一页面的_csv.php(一体式表单),它将再次循环文件并检查
是否(isset($\u post[$file])
文件名是$\u post数组中的一个键?从哪里寄来的?@Dagon你什么意思?表单标记中是我的php块,它通过扫描目录创建按钮和按钮旁边的文本。当按下一个按钮时,表单将post导入同一页面的_csv.php(一个多功能表单),它将再次循环文件并检查
如果(isset($\u post[$file]))
我的复选框也不会在帖子中出现,这可能是相同的问题吗?请打印整个$\u post或$\u请求数组print\r($\u post),它将显示参数名称,而且我的复选框不会在帖子中出现,这可能是相同的问题吗?请打印整个$\u post或$\u请求数组print\r($\u post),它将显示参数名称