Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Images

PHP Link Bug

images php coding issues or problems here.

Moderators: macek, egami, gesf

PHP Link Bug

Postby dylanm312 » Sun Mar 24, 2013 9:52 pm

Hi all,

First thing's first: I've got to try out one of these smileys, so... :help:

That was fun.



I've been playing around with using PHP to process HTML forms, and my earlier code looked like this:

Code: Select all
<?php
   $gender = $_POST['gender'];
   
   if($gender == 'Male'){
      echo('male');
   }else {
      echo('female');
   }
   echo('<a href="/index.html">Return</a>');
?>


Really, all this does is if the user selected "Male" from the drop-down menu he will receive a nice little message reminding him that he is male, and vice versa. The user also has a return link to go back to the homepage.

My problems arise when I try to replace the text with images:

Code: Select all
<?php
   $gender = $_POST['gender'];
   
   if($gender == 'Male'){
      echo('<img src="/images/its_a_boy.jpg"');
   }else {
      echo('<img src="/images/its_a_girl.jpg"');
   }
   echo('<a href="/index.html">Return</a>');
?>


The link becomes not a link and instead turns into plain text. All efforts to replace its link-ness have failed.

Any ideas?
Dylan
dylanm312
New php-forum User
New php-forum User
 
Posts: 1
Joined: Sun Mar 24, 2013 9:46 pm

Re: PHP Link Bug

Postby seandisanti » Thu Mar 28, 2013 10:30 pm

if you were manually writing your markup instead of echoing it out; wouldn't you close your image tags with greater than signs?
Code: Select all

          
echo('<img src="/images/its_a_boy.jpg"');//see what i mean?
 
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: PHP Link Bug

Postby swarups » Mon Apr 15, 2013 1:30 am

Hi dylanm312,

Here your image tag is not closed. So the link comes as a text. Please see the code below: :)

Code: Select all
$gender = $_POST['gender'];
   

if($gender == 'Male'){
      echo('<img src="/images/its_a_boy.jpg"/>');
   }else {
      echo('<img src="/images/its_a_girl.jpg" />');
   }
   echo('<a href="/index.html">Return</a>');


Thanks
Swarup
swarups
New php-forum User
New php-forum User
 
Posts: 20
Joined: Tue Mar 06, 2012 11:05 pm


Return to PHP coding => Images

Who is online

Users browsing this forum: No registered users and 6 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron