[英]Nothing is displayed on the screen after form submission
I've looked and tried many of the solutions here and on other sites but I am still befuddled (still doing the PHP school thing, but something is eluding me).我已经在这里和其他网站上查看并尝试了许多解决方案,但我仍然感到困惑(仍在做 PHP 学校的事情,但有些东西让我望而却步)。
I have a page that a user can select multiple check boxes and it builds the data:我有一个页面,用户可以选择多个复选框并构建数据:
<?php
$username = $_POST['username'];
$filename = "../files/Awards_$username.txt";
$award = $_POST['awardrec'];
file_put_contents($filename, print_r($award, true), FILE_APPEND)
?>
Simple enough.足够简单。 It writes the data as:它将数据写为:
Array
(
[0] => Value1
[1] => Value2
[2] => Value3
[3] => Value4
[4] => Value5
[5] => Value6
)
But nothing I seem to do results in anything being displayed.但是我似乎没有做任何事情都会显示任何内容。 No error messages;没有错误信息; nothing, just a white page.没什么,只是一个白页。
Ultimately it's just a page that will read the data and display a graphic associated with the value.最终它只是一个页面,它将读取数据并显示与值关联的图形。
Where would a good article on this type of operation be?关于这种类型的操作的好文章在哪里?
I am not sure what exactly you are trying to achieve but this should help at least a bit hopefully in the right direction :我不确定你到底想要达到什么目标,但这应该至少在正确的方向上有所帮助:
<?php
// For test
// $_POST['username'] = 'some_username';
// $_POST['awardrec'] = array( 'award_one' ,'award_two' );
if( ! isset( $_POST['username'] ) )
{
echo 'username is not set';
exit;
}
$username = trim( $_POST['username'] );
if( $username == '' )
{
echo 'username is empty';
exit;
}
$filename = "../files/Awards_$username.txt";
if( ! isset( $_POST['awardrec'] ) )
{
echo 'awardrec is not set';
exit;
}
$award = $_POST['awardrec'];
// Save the contents to file
file_put_contents( $filename ,print_r( $award ,true ) ,FILE_APPEND );
// Display contents
echo 'Username : ' ,$username ,'<br>';
echo 'Awards :' ,'<br>';
foreach( $award as $value )
{
echo $value .'<br>';
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.