开发者

passing href attributes to another php page

.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 th开发者_如何学运维at 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!


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.


You can send the parameter to picture.php via GET

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


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); 


<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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜