我对用于添加链接的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);
?>
我想在我的网站上使用此表单,以便访问者可以添加他们的链接。我不明白如何在HTML行中使用$ _POST ['field1']。
感谢您的时间和关注。
答案 0 :(得分:0)
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');
}
?>
答案 1 :(得分:0)
<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>':
?>