dongya0914 2013-01-30 21:05
浏览 22

PHP变量链接/显示

I'm passing variables from my Flash MP3 player to a PHP script to record what songs have played. Now I want the PHP script to display one varable and include it in an Amazon link.

This is what I have but can't seem to get it to work.

<?php
$var1  = $_POST['var1']; //get the Artist Name and Title from Flash and store it in a PHP variable
$var2 = $_POST['var2']; //ignored
//This lines combines the two variables into one string. 
//To concatinate vars in PHP use a period or dot ".", much like Flash uses a plus sign "+". 

$add = $var1 . "+" . $var2 . "|";
//opens or creates (if it doesn't already exist) our text file (songsplayed.txt) 
//for writing (not reading) and places the pointer at the end.
$open = fopen('songsplayed.txt', 'a'); 
//writes to our specified file our string
$write = fwrite($open, $add); 

echo $var1;
echo

<a type="amzn" search=\"$var1\" category="music">
<img border="0" src="/buttons/buy-now-button-amazon.png" alt="Buy now @ Amazon"></a>
?>
  • 写回答

2条回答 默认 最新

  • dsdsds12222 2013-01-30 21:09
    关注

    You seem to be trying to echo HTML to the page without surrounding it with quotes. Try this instead:

    <?php
    $var1  = $_POST['var1']; //get the Artist Name and Title from Flash and store it in a PHP variable
    $var2 = $_POST['var2']; //ignored
    //This lines combines the two variables into one string. 
    //To concatinate vars in PHP use a period or dot ".", much like Flash uses a plus sign "+". 
    
    $add = $var1 . "+" . $var2 . "|";
    //opens or creates (if it doesn't already exist) our text file (songsplayed.txt) 
    //for writing (not reading) and places the pointer at the end.
    $open = fopen('songsplayed.txt', 'a'); 
    //writes to our specified file our string
    $write = fwrite($open, $add); 
    
    echo $var1;
    ?>
    <a type="amzn" search="<?php echo $var1; ?>" category="music">
    <img border="0" src="/buttons/buy-now-button-amazon.png" alt="Buy now @ Amazon"></a>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?