Saranya Thirumeni Saranya Thirumeni - 1 year ago 90
PHP Question

Passing multiple php variable using img src url

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


$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


$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 Source

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


<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" />


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" />';


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" />


<img src="trend_g.php?element_3=<?php echo $queue;?>&month=<?php echo $std_mm;?>&year=<?php echo $std_yy;?>" />
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download