如何添加具有多个 php 值的 href link?
How to add href link with multiple php values?
我对添加 link 的 php Web 表单没有什么问题。
我希望表单将值记录在:
<a href="$_POST['field1']" target="_blank" rel="nofollow" title=".$_POST['field3']">.$_POST['field2']</a>
但我不知道该怎么做才能正常工作。
我的代码是...
HTML 表单代码:
<form action="myprocessingscript.php" method="POST">
<p>Уеб Сайт: </p><input name="field1" type="text" placeholder="https://www.tvoiasait.com/" /><br />
<p>Ключова дума: </p><input name="field2" type="text" placeholder="Моят Личен Блог" /><br />
<p>Описание: </p><input name="field3" type="text" placeholder="Личен Блог за интересни неща" /><br />
<br /><input type="submit" name="submit" value="Добави сайта">
</form>
myprocessingscript.php代码为:
<?php
if(isset($_POST['field1']) && isset($_POST['field2']) && isset($_POST['field3'])) {
$data = '<a href='.$_POST["field1"]' target='_blank' rel='nofollow' title='.$_POST["field3"]'>.$_POST["field2"]</a>' . "\n";
$ret = file_put_contents('mydata.txt', $data, FILE_APPEND | LOCK_EX);
if($ret === false) {
die('There was an error writing this file');
}
else {
echo "$ret bytes written to file";
}
}
else {
die('no post data to process');
}
?>
我的显示表单记录代码是:
<?php
$myfile = fopen("mydata.txt", "r") or die("Unable to open file!");
while(!feof($myfile)) {
echo fgets($myfile);
}
fclose($myfile);
?>
我想在我的网站上使用此表格,以便访问者可以将他们的 link 添加到其中。我不明白如何在 HTML 行中使用 $_POST['field1']。
感谢您的时间和关注。
This below "" string addition could solve your problem.
<?php
if(isset($_POST['field1']) && isset($_POST['field2']) && isset($_POST['field3'])) {
$data = '<a href="'.$_POST["field1"].'" target="_blank" rel="nofollow" title="'.$_POST["field3"].'">'.$_POST["field2"].'</a>' . "\n";
$ret = file_put_contents('mydata.txt', $data, FILE_APPEND | LOCK_EX);
if($ret === false) {
die('There was an error writing this file');
} else {
echo "$ret bytes written to file";
}
}
else {
die('no post data to process');
}
?>
<a href="<?php echo $_POST['field1']?>" target="_blank" rel="nofollow" title="<?php echo $_POST['field3'] ?>"><?php echo $_POST['field2'] ?></a>
或
<?php
echo '<a href="' . $_POST['field1'] . '" target="_blank" rel="nofollow"
title="' . $_POST['field3'] . '"><' . $_POST['field2'] . '</a>':
?>
我对添加 link 的 php Web 表单没有什么问题。
我希望表单将值记录在:
<a href="$_POST['field1']" target="_blank" rel="nofollow" title=".$_POST['field3']">.$_POST['field2']</a>
但我不知道该怎么做才能正常工作。
我的代码是... HTML 表单代码:
<form action="myprocessingscript.php" method="POST">
<p>Уеб Сайт: </p><input name="field1" type="text" placeholder="https://www.tvoiasait.com/" /><br />
<p>Ключова дума: </p><input name="field2" type="text" placeholder="Моят Личен Блог" /><br />
<p>Описание: </p><input name="field3" type="text" placeholder="Личен Блог за интересни неща" /><br />
<br /><input type="submit" name="submit" value="Добави сайта">
</form>
myprocessingscript.php代码为:
<?php
if(isset($_POST['field1']) && isset($_POST['field2']) && isset($_POST['field3'])) {
$data = '<a href='.$_POST["field1"]' target='_blank' rel='nofollow' title='.$_POST["field3"]'>.$_POST["field2"]</a>' . "\n";
$ret = file_put_contents('mydata.txt', $data, FILE_APPEND | LOCK_EX);
if($ret === false) {
die('There was an error writing this file');
}
else {
echo "$ret bytes written to file";
}
}
else {
die('no post data to process');
}
?>
我的显示表单记录代码是:
<?php
$myfile = fopen("mydata.txt", "r") or die("Unable to open file!");
while(!feof($myfile)) {
echo fgets($myfile);
}
fclose($myfile);
?>
我想在我的网站上使用此表格,以便访问者可以将他们的 link 添加到其中。我不明白如何在 HTML 行中使用 $_POST['field1']。
感谢您的时间和关注。
This below "" string addition could solve your problem.
<?php
if(isset($_POST['field1']) && isset($_POST['field2']) && isset($_POST['field3'])) {
$data = '<a href="'.$_POST["field1"].'" target="_blank" rel="nofollow" title="'.$_POST["field3"].'">'.$_POST["field2"].'</a>' . "\n";
$ret = file_put_contents('mydata.txt', $data, FILE_APPEND | LOCK_EX);
if($ret === false) {
die('There was an error writing this file');
} else {
echo "$ret bytes written to file";
}
}
else {
die('no post data to process');
}
?>
<a href="<?php echo $_POST['field1']?>" target="_blank" rel="nofollow" title="<?php echo $_POST['field3'] ?>"><?php echo $_POST['field2'] ?></a>
或
<?php
echo '<a href="' . $_POST['field1'] . '" target="_blank" rel="nofollow"
title="' . $_POST['field3'] . '"><' . $_POST['field2'] . '</a>':
?>