duandian2725 2015-04-08 11:10
浏览 32

如何点击图片href并转到新页面。 并显示来自phpmyadmin的信息

I am trying to use a image from a folder; click on it and make it select an id from the image to display information from phpmyadmin.

This is my php where I call for the info:

<meta charset="UTF-8">
<?php
include "dbcon.php";

$id = $_POST['val'];
try {
    $sql = "select name,discription FROM upcoming_events where id = '$id'";//if i put 1 or 2 for the $id it works
        $result = $pdo->query($sql);
} catch (PDOException $ex) {
    echo 'Error fetching scores: '.$e->getMessage();
    }

        $row = $result -> fetch();
    $name = $row[0];
    $discription = $row[1];

    $gildiUt = "Nafnið er $name<br> lýsing er $discription";

?>

<?php 
include "../php/upcoming.php";
echo $gildiUt;
 ?>

This is the error I get when I try to run it. It does not show $name of $discription but it does if I but in 1 or 2 for $id.

Notice: Undefined index: val in

E:\utsdata\hopar\GRU_H4\php\upcoming.php on line 5 Nafnið er lýsing er

Nafnið er lýsing er

This is my html where the images is and the value is used to find the id but it does not find the id. I am not sure if my value works for a image.

     <form action="upcoming.php" method="post">
         <input type"image" name"val" value="1"> <li class="col-lg-3 col-md-2 col-sm-3 col-xs-12"><a href="../upcoming/upcoming.html.php"><img src="../myndir/upcoming/mynd1.png" alt=""width="200" height="300"></a></li>
         <input type"image" name"val" value="2"> <li class="col-lg-3 col-md-2 col-sm-3 col-xs-12"><a href="../upcoming/upcoming.html.php"><img src="../myndir/upcoming/mynd2.png" alt=""width="200" height="300"></a></li>
         <input type"image" name"val" value="3"> <li class="col-lg-3 col-md-2 col-sm-3 col-xs-12"><a href="../upcoming/upcoming.html.php"><img src="../myndir/upcoming/mynd3.png" alt=""width="200" height="300"></a></li>
         <input type"image" name"val" value="4"> <li class="col-lg-3 col-md-2 col-sm-3 col-xs-12"><a href="../upcoming/upcoming.html.php"><img src="../myndir/upcoming/mynd4.png" alt=""width="200" height="300"></a></li>
         <input type"image" name"val" value="5"> <li class="col-lg-3 col-md-2 col-sm-3 col-xs-12"><a href="../upcoming/upcoming.html.php"><img src="../myndir/upcoming/mynd5.png" alt=""width="200" height="300"></a></li>
         <input type"image" name"val" value="6"> <li class="col-lg-3 col-md-2 col-sm-3 col-xs-12"><a href="../upcoming/upcoming.html.php"><img src="../myndir/upcoming/mynd6.png" alt=""width="200" height="300"></a></li>
         <input type"image" name"val" value="7"> <li class="col-lg-3 col-md-2 col-sm-3 col-xs-12"><a href="../upcoming/upcoming.html.php"><img src="../myndir/upcoming/mynd7.png" alt=""width="200" height="300"></a></li>
         <input type"image" name"val" value="8"> <li class="col-lg-3 col-md-2 col-sm-3 col-xs-12"><a href="../upcoming/upcoming.html.php"><img src="../myndir/upcoming/mynd8.png" alt=""width="200" height="300"></a></li>
         <input type"image" name"val" value="9"> <li class="col-lg-3 col-md-2 col-sm-3 col-xs-12"><a href="../upcoming/upcoming.html.php"><img src="../myndir/upcoming/mynd9.png" alt="" width="200" height="300"></a></li>
         <input type"image" name"val" value="10"> <li class="col-lg-3 col-md-2 col-sm-3 col-xs-12"><a href="../upcoming/upcoming.html.php"><img src="../myndir/upcoming/mynd10.png" alt=""width="200" height="300"></a></li>
         <input type"image" name"val" value="11"> <li class="col-lg-3 col-md-2 col-sm-3 col-xs-12"><a href="../upcoming/upcoming.html.php"><img src="../myndir/upcoming/mynd11.png" alt="" width="200" height="300"></a></li>
         <input type"image" name"val" value="12"> <li class="col-lg-3 col-md-2 col-sm-3 col-xs-12"><a href="../upcoming/upcoming.html.php"><img src="../myndir/upcoming/mynd12.png" alt=""width="200" height="300"></a></li>
      </form>
  • 写回答

1条回答 默认 最新

  • duanba8070 2015-04-08 11:34
    关注

    An <a> tag will make a GET request to the server.

    Try having a link like this:

    <a href="../upcoming/upcoming.html.php?val=1" />
    

    and then accessing the variable using $_GET[val]

    As the comments have suggested, you are not binding your parameters which makes your entire site vulnerable to SQL injection. Try taking a look this

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分