dsij89625 2013-03-12 15:52
浏览 28
已采纳

在php中将所选链接作为GET参数发送

I am working on a form where i write information about a movie, and post it to a textfile. I then echo it in a list with links to the same file. I know want to give the links a GET parameter, so that the chosen links name gets sent as a GET parameter. I cant seem to get it right.

<!DOCTYPE html>

<html>

<head>
<title>Inlämning3</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript" src="jQuery.js" >
</script>
<script type="text/javascript" src="valideraFilmer.js" >
</script>


</head>

<body>

<?php
// Skriva film och info till en textfil
if( isset ($_POST['name'])){
    $name = $_POST['name'];
    $grade = $_POST['options'];
    $link = $_POST['link'];
    $pic = $_POST['pic'];
    $story = $_POST['story'];

    $myFile = "filmer.txt";
    $handle = fopen($myFile, 'a');

    if(!empty($name)){
        fwrite($handle, $name. ";");
        fwrite($handle, $grade. ";");
        fwrite($handle, $link. ";");
        fwrite($handle, $pic. ";");
        fwrite($handle, $story. "
");
        fclose($handle);
    }
}
?>

<div id="page">
    <?php
        include("header.php");
    ?>
    <div id="leftbar">
        <form id="form" method="post" action="Filmer-PHP.php" >
            <fieldset>
                <legend>Lägg till en film:</legend>
                Titel:
                <br><input type="text" name="name" id="name"><br>
                Betyg:
                <br><select id="options" name="options">
                    <option value="0">Välj betyg här...</option>
                    <option value="*"> *</option>
                    <option value="**"> **</option>
                    <option value="***"> ***</option>
                    <option value="****"> ****</option>
                    <option value="*****"> *****</option>                       
                </select>
                <br>
                Länk till imdb:
                <br><input type="text" name="link" id="link"><br>
                Länk till bild:
                <br><input type="text" name="pic" id="pic"><br>
                Filmens handling:
                <br><textArea cols="20" rows="3" name="story" id="story"></textarea><br>
                <br><input type="submit" name="button" value="Spara film" id="button">
            </fieldset>
        </form>
    </div>
    <div id="rightbar">
        <h2>Filmer</h2>

        <?php
        // Läsa av och visa titel och betyg
            $readin = file('filmer.txt');
            $ul = '<ul id="films">';
            echo $ul;
            foreach($readin as $fName){
                $lineSplit = explode(";", $fName);
                echo '<li>'.'<a href="Filmer-PHP.php?filmer=$lineSplit[0]">'.$lineSplit[0].'<span>'.$lineSplit[1].'</span>'.'</a>'.'</li>';
            }

        ?>

        <?php
        // Läsa av och visa detaljerad info om filmer
        ?>

    </div>
        <?php
            include("footer.php");
        ?>
</div>

</body>

</html>
  • 写回答

1条回答 默认 最新

  • dp19001 2013-03-12 15:56
    关注

    Variables in single quotes are not expanded, so if you write this:

    echo '<a href="Filmer-PHP.php?filmer=$lineSplit[0]">'
    

    This will end up as

    <a href="Filmer-PHP.php?filmer=$lineSplit[0]">
    

    You probably want $lineSplit[0] to be replaced by the value of that variable. Use either double quotes

    echo "<a href='Filmer-PHP.php?filmer=$lineSplit[0]'>"
    

    or put it outside of the quotes

    echo '<a href="Filmer-PHP.php?filmer=' . $lineSplit[0] . '">'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)