Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.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 - Fatal编程技术网

究竟为什么会赢';我的php页面不工作吗?

究竟为什么会赢';我的php页面不工作吗?,php,Php,my.php文件的当前状态: 我有两个问题:第一,当页面加载时,所有我的时间字段都被禁用(见上面的站点)。其次,当我点击submit时,我得到以下错误:第8行中为foreach()提供的参数无效 有人能帮我修一下吗 My .txt looks like this: 8:00 am|Rich Jones 9:00 am|Available ...... 5:00 pm|Available 代码: 并且您缺少一个目录分隔符: public_htmltest.txt $filename =

my.php文件的当前状态:

我有两个问题:第一,当页面加载时,所有我的时间字段都被禁用(见上面的站点)。其次,当我点击submit时,我得到以下错误:第8行中为foreach()提供的参数无效

有人能帮我修一下吗

 My .txt looks like this:
 8:00 am|Rich Jones
 9:00 am|Available
 ......
 5:00 pm|Available
代码:


并且您缺少一个目录分隔符:

public_htmltest.txt

$filename = getcwd() . "test.txt";
试着这样做:

$filename = getcwd() . DIRECTORY_SEPARATOR . "test.txt";
:为第8行中的foreach()提供的参数无效

此行导致您的错误:

$lines = file( $filename , FILE_IGNORE_NEW_LINES );
您的
$lines
变量为空或不是数组。

给您:

只要确保test.txt是可读写的

<?php


if (isset($_POST['submit']))
{ 
    $find_name = $_POST['name'];
    $find_time = urldecode($_POST['time']);
    $lines_handle = fopen("test.txt", "r");
    while (($buffer = fgets($lines_handle, 4096)) !== false)
    {
        list($time, $name) = explode('|', $buffer);
        $time = trim($time);
        $name = trim($name);
        if ($time == $find_time && $name == "Available")
        {
            $lines[] = $time."|".$find_name;
        }
        else
        {
            $lines[] = $time."|".$name;
        }
    }
    $lines_handle = fopen("test.txt", "w");
    foreach ($lines as $line)
    {
        fwrite($lines_handle, $line . "\n");    
    }
}
// Read the file into an array
$users_handle = fopen("test.txt", "r");
//$users = file("test.txt");
$hours_taken = array();

// Begin Table
echo "<table align = 'center' border='2' width='50%' cellspacing='0' 
    cellpadding='0'>";
echo "<caption> Sign/Up Sheet </caption>";
echo "<tr><td><b>Time</b></td><td><b>Name</b></td></tr>";

// Cycle through the array
while (($buffer = fgets($users_handle, 4096)) !== false)
{
    // Parse the line
    list($time, $name) = explode('|', $buffer);
    if (trim($name) != "Available")
    {
        array_push($hours_taken, $time);    
    }

    // Remove newline 
    $name = trim($name);

    // Output the data in a two column table
    echo "<tr><td>".$time."</td><td>".$name."</td></tr>";

}
echo "</table>";

// Assuming same order of rows in users.txt
$hours = array('8:00 am', '9:00 am', '10:00 am','11:00 am', '12:00 pm', '1:00 pm', 
    '2:00 pm', '3:00 pm', '4:00 pm', '5:00 pm'); 

$i = 1;
echo '<form method="post" action="">';
echo 'Name:<input type ="text" id="name" name="name" size="20" maxlength="40" />';
echo '<select name="time"><option selected>-- Select time --</option>';
foreach ($hours as $hour) {
if (in_array($hour, $hours_taken)) {
    echo '<option disabled=disabled>'. $hour .'</option>';
}
else {
    echo '<option value='. urlencode($hour) .'>'. $hour .'</option>';
}
$i++;
}
echo '<input type="submit" id="submit" name="submit" value="Sign Up!" />';
echo '</form>';



  ?>

我在那里的任何地方都看不到函数…
;)
对于禁用的字段,请尝试使用$\u GET或$\u REQUEST。至于第二个问题,在设置完每个字段后,对其进行回显,并在foreach中放置一些回显,以查看变量的情况。foreach()错误是因为它没有读取test.txt文件。不要使用
getcwd()
只需使用$filename='./test.txt“您是否转储了
$hours\
以确保其中填充了信息?
错误报告(E|u ALL | E|u STRICT);ini设置(“显示错误”,真)<?php


if (isset($_POST['submit']))
{ 
    $find_name = $_POST['name'];
    $find_time = urldecode($_POST['time']);
    $lines_handle = fopen("test.txt", "r");
    while (($buffer = fgets($lines_handle, 4096)) !== false)
    {
        list($time, $name) = explode('|', $buffer);
        $time = trim($time);
        $name = trim($name);
        if ($time == $find_time && $name == "Available")
        {
            $lines[] = $time."|".$find_name;
        }
        else
        {
            $lines[] = $time."|".$name;
        }
    }
    $lines_handle = fopen("test.txt", "w");
    foreach ($lines as $line)
    {
        fwrite($lines_handle, $line . "\n");    
    }
}
// Read the file into an array
$users_handle = fopen("test.txt", "r");
//$users = file("test.txt");
$hours_taken = array();

// Begin Table
echo "<table align = 'center' border='2' width='50%' cellspacing='0' 
    cellpadding='0'>";
echo "<caption> Sign/Up Sheet </caption>";
echo "<tr><td><b>Time</b></td><td><b>Name</b></td></tr>";

// Cycle through the array
while (($buffer = fgets($users_handle, 4096)) !== false)
{
    // Parse the line
    list($time, $name) = explode('|', $buffer);
    if (trim($name) != "Available")
    {
        array_push($hours_taken, $time);    
    }

    // Remove newline 
    $name = trim($name);

    // Output the data in a two column table
    echo "<tr><td>".$time."</td><td>".$name."</td></tr>";

}
echo "</table>";

// Assuming same order of rows in users.txt
$hours = array('8:00 am', '9:00 am', '10:00 am','11:00 am', '12:00 pm', '1:00 pm', 
    '2:00 pm', '3:00 pm', '4:00 pm', '5:00 pm'); 

$i = 1;
echo '<form method="post" action="">';
echo 'Name:<input type ="text" id="name" name="name" size="20" maxlength="40" />';
echo '<select name="time"><option selected>-- Select time --</option>';
foreach ($hours as $hour) {
if (in_array($hour, $hours_taken)) {
    echo '<option disabled=disabled>'. $hour .'</option>';
}
else {
    echo '<option value='. urlencode($hour) .'>'. $hour .'</option>';
}
$i++;
}
echo '<input type="submit" id="submit" name="submit" value="Sign Up!" />';
echo '</form>';



  ?>