简体   繁体   中英

How to add href link with multiple php values?

I have little problem with php web form for add link.

I want the form to record the values in:

<a href="$_POST['field1']" target="_blank" rel="nofollow" title=".$_POST['field3']">.$_POST['field2']</a>

But I don't know how to do it to work correctly.

My code is... HTML form code:

    <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 code is:

<?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');
}
?>

and my code for show form records is:

   <?php
    $myfile = fopen("mydata.txt", "r") or die("Unable to open file!");
    while(!feof($myfile)) {
    echo fgets($myfile);
    }
    fclose($myfile);
    ?>

I want to use this form on my website so that visitors can add their link to them. I don't understand how to use $_POST['field1'] in HTML row.

Thanks for your time and attention.

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>

or

<?php

echo '<a href="' . $_POST['field1'] . '" target="_blank" rel="nofollow" 
title="' . $_POST['field3'] . '"><' . $_POST['field2'] . '</a>':

?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM