passing href attributes to another php page

2019-08-01 23:48发布

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

标签: php anchor
4条回答
地球回转人心会变
2楼-- · 2019-08-02 00:02
<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.

查看更多
我只想做你的唯一
3楼-- · 2019-08-02 00:03

You can send the parameter to picture.php via GET

<a href="picture.php?id=894754093857">Blah!</a>
查看更多
Deceive 欺骗
4楼-- · 2019-08-02 00:08

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); 
查看更多
你好瞎i
5楼-- · 2019-08-02 00:12

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.

查看更多
登录 后发表回答