如果我的所有$ _GET值都不为null,我试图让一块php运行。 我的代码如下:
if (!isset($_REQUEST['name'])
|| !isset($_REQUEST['number'])
|| !isset($_REQUEST['section'])
|| !isset($_REQUEST['email'])){
//open files and write
$email_file = fopen("emails","a+");
$url_file = fopen("urls","a+");
$courses_file = fopen("courses","a+");
fwrite($email_file, $_REQUEST['email'] . "\n");
fwrite($url_file, $url . "\n");
fwrite($courses_file, $_REQUEST['name'] . " " . $_REQUEST['number'] . " " . $_REQUEST['section'] . "\n");
}
这似乎根本不起作用。无论我传递的是什么,都没有任何内容写入我的文件。如果我删除if语句,代码适用于编写文件,所以我知道它在我的条件中的某个地方。
答案 0 :(得分:1)
if (!empty($_GET['name'])
&& !empty($_GET['number'])
&& !empty($_GET['section'])
&& !empty($_GET['email'])){
//open files and write
file_put_contents('emails.txt', $_GET['email'] . "\n", FILE_APPEND | LOCK_EX);
file_put_contents('urls.txt', $url . "\n", FILE_APPEND | LOCK_EX); // Where does $url come from??? It's not coming from the $_GET params.
file_put_contents('courses.txt', $_GET['name'] . " " . $_GET['number'] . " " . $_GET['section'] . "\n", FILE_APPEND | LOCK_EX);
}