Saranya Thirumeni Saranya Thirumeni - 3 months ago 11
PHP Question

Passing multiple php variable using img src url

I am new to PHP. Creating an application with multiple page.

Sample1.php

$queue=$_POST['element_3'];//Customer name
$month=(int)$_POST['month'];//month as value 06
$std_yy = $_POST['year'];// 2016
<img src="trend_g.php?element_3=$queue&month=$std_mm&year=$std_yy" /> //does not work
<img src="trend_g.php?element_3=Apple&month=06&year=2016" />//works


trend_g.php

$queue=$_GET['element_3'];
$month=(int)$_GET['month'];
$std_yy = $_GET['year'];


Please help me to pass the variables through URL. Also I did try the below too.

<img src="trend_g.php?element_3='.$queue.'&month='.$std_mm.'&year='.$std_yy.'" /> //didnt work.


Looked into various options, but I am stuck here. Any help is highly appreciated!

Answer

You're not calling the img element as PHP while still in PHP, ie before the closing PHP tag (?>)

change

<img src="trend_g.php?element_3=$queue&month=$std_mm&year=$std_yy" />

<img src="trend_g.php?element_3=Apple&month=06&year=2016" />

to

echo '<img src="trend_g.php?element_3='.$queue.'&month='.$std_mm.'&year='.$std_yy.'" /> ';

echo '<img src="trend_g.php?element_3=Apple&month=06&year=2016" />';

EDIT

If you did close off the php then you need to change

<img src="trend_g.php?element_3=$queue&month=$std_mm&year=$std_yy" />

To

<img src="trend_g.php?element_3=<?php echo $queue;?>&month=<?php echo $std_mm;?>&year=<?php echo $std_yy;?>" />