单击提交按钮后的操作 (php)
Action after click on submit button (php)
我在 php 语言上创建了一个页面,其中包含文件列表、存储在文件夹中和按钮提交。当我按下提交按钮时,文件夹中存储的文件被发送到文件服务器。我想添加段落,我可以在其中添加下载文件的下载 link。我写了一个小函数 display(),如果我点击提交按钮,显示 2 个字符串,"Download link:" 和变量 $text,我在其中存储下载 link,但是这个函数根本不起作用,它单击提交按钮后无法显示简单文本,我不知道为什么。帮助我了解可能是什么问题。
重要时刻,我只能用php语言
问题是我没有调用函数
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>For test</title>
</head>
<body>
<?php
function display()
{
$text = 'link';
print "Download link: ";
echo $text;
}
if(isset($_POST['submit']))
{
display();
}
?>
<div style="border-bottom: 2px solid black; border-top: 2px solid black; background-color: white; width: 25%; text-align: center; display: block; margin: auto; ">
<?php foreach ($files as $file) { ?>
<p style="text-align: inherit"><?php echo $file; ?></p>
<?php } ?>
</div>
<p><?php echo $text; ?></p>
<div style="text-align: center; float: inherit; margin-top: 5%">
<form method="post" action="">
<input type="submit" value="Upload" name="submit"><br><br>
</form>
</div>
</body>
</html>
您的脚本有错误
@
<body">
should be
<body>
然后你需要开始 php 标签作为
<?php
您错过了 PHP 标记语法。每个 php 函数和代码都必须在 PHP 标记中。更新代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>For test</title>
</head>
<body>
<?php
function display()
{
$text = 'link';
print "Download link: ";
echo $text;
}
if(isset($_POST['submit']))
{
display();
}
?>
<div style="border-bottom: 2px solid black; border-top: 2px solid black; background-color: white; width: 25%; text-align: center; display: block; margin: auto; ">
<?php foreach ($files as $file) { ?>
<p style="text-align: inherit"><?php echo $file; ?></p>
<?php } ?>
</div>
<p><?php echo $text; ?></p>
<div style="text-align: center; float: inherit; margin-top: 5%">
<form method="post" action="">
<input type="submit" value="Upload" name="submit"><br><br>
</form>
</div>
</body>
</html>
更正后的代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>For test</title>
</head>
<body>
<?php
function display()
{
$text = 'link';
print "Download link: ";
echo $text;
}
if(isset($_POST['submit']))
{
display();
}
?>
<div style="border-bottom: 2px solid black; border-top: 2px solid black; background-color: white; width: 25%; text-align: center; display: block; margin: auto; ">
<?php foreach ($files as $file) { ?>
<p style="text-align: inherit"><?php echo $file; ?></p>
<p> <?php display(); ?> </p>
</div>
<p><?php echo $text; ?></p>
<div style="text-align: center; float: inherit; margin-top: 5%">
<form method="post" action="">
<input type="submit" value="Upload" name="submit"><br><br>
</form>
</div>
</body>
</html>
我在 php 语言上创建了一个页面,其中包含文件列表、存储在文件夹中和按钮提交。当我按下提交按钮时,文件夹中存储的文件被发送到文件服务器。我想添加段落,我可以在其中添加下载文件的下载 link。我写了一个小函数 display(),如果我点击提交按钮,显示 2 个字符串,"Download link:" 和变量 $text,我在其中存储下载 link,但是这个函数根本不起作用,它单击提交按钮后无法显示简单文本,我不知道为什么。帮助我了解可能是什么问题。
重要时刻,我只能用php语言
问题是我没有调用函数
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>For test</title>
</head>
<body>
<?php
function display()
{
$text = 'link';
print "Download link: ";
echo $text;
}
if(isset($_POST['submit']))
{
display();
}
?>
<div style="border-bottom: 2px solid black; border-top: 2px solid black; background-color: white; width: 25%; text-align: center; display: block; margin: auto; ">
<?php foreach ($files as $file) { ?>
<p style="text-align: inherit"><?php echo $file; ?></p>
<?php } ?>
</div>
<p><?php echo $text; ?></p>
<div style="text-align: center; float: inherit; margin-top: 5%">
<form method="post" action="">
<input type="submit" value="Upload" name="submit"><br><br>
</form>
</div>
</body>
</html>
您的脚本有错误 @
<body">
should be
<body>
然后你需要开始 php 标签作为
<?php
您错过了 PHP 标记语法。每个 php 函数和代码都必须在 PHP 标记中。更新代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>For test</title>
</head>
<body>
<?php
function display()
{
$text = 'link';
print "Download link: ";
echo $text;
}
if(isset($_POST['submit']))
{
display();
}
?>
<div style="border-bottom: 2px solid black; border-top: 2px solid black; background-color: white; width: 25%; text-align: center; display: block; margin: auto; ">
<?php foreach ($files as $file) { ?>
<p style="text-align: inherit"><?php echo $file; ?></p>
<?php } ?>
</div>
<p><?php echo $text; ?></p>
<div style="text-align: center; float: inherit; margin-top: 5%">
<form method="post" action="">
<input type="submit" value="Upload" name="submit"><br><br>
</form>
</div>
</body>
</html>
更正后的代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>For test</title>
</head>
<body>
<?php
function display()
{
$text = 'link';
print "Download link: ";
echo $text;
}
if(isset($_POST['submit']))
{
display();
}
?>
<div style="border-bottom: 2px solid black; border-top: 2px solid black; background-color: white; width: 25%; text-align: center; display: block; margin: auto; ">
<?php foreach ($files as $file) { ?>
<p style="text-align: inherit"><?php echo $file; ?></p>
<p> <?php display(); ?> </p>
</div>
<p><?php echo $text; ?></p>
<div style="text-align: center; float: inherit; margin-top: 5%">
<form method="post" action="">
<input type="submit" value="Upload" name="submit"><br><br>
</form>
</div>
</body>
</html>