passing href attributes to another php page

…衆ロ難τιáo~ 提交于 2019-12-13 00:22:53

问题


.a little help guys..

I have an index.php page which contains tags which when clicked opens up picture.php. .my picture.php is a page that retrieves images from a certain database depending on what is the idno.

.what i want to do is to add an "idno" attribute on my anchor tag that when the user clicks a certain tag the index.php sends the idno to my picture.php so that the picture.php knows what image to fetch from the database. help pls!


回答1:


So for your anchor tag, could you do something like this?

<?php
    $url = "pictures.php?idno=" . idno;
    echo "<a href=\"" . $url . "\">Click Me</a>";
?>

Now in your pictures.php file, you can read the ID like this:

$idno = $_GET['idno'];

The only thing to watch out for is to make sure you sanitize that input, before you pass it off to a database query so you aren't vulnerable to a SQL injection attack.




回答2:


You can send the parameter to picture.php via GET

<a href="picture.php?id=894754093857">Blah!</a>



回答3:


You could use GET to pass idno to pictures.php

so your link would look like this:

<a href='/picture.php?idno=12345678'>My Picture Tag</a>

In your picture.php:

$idno = $_GET['idno']; 

Make sure you sterilize $idno before using it in a MySQL query. If idno is a number, then you can also check if it's an integer:

$isInt = is_int($idno); 



回答4:


<a href="picture.php?idno=<?php echo $idno ?>">Picture # <?php echo $idno ?></a>

Figuring out how to set $idno is left as an exercise to the OP.



来源:https://stackoverflow.com/questions/5160247/passing-href-attributes-to-another-php-page

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!