Jump to content

Using an img src in php


AikenDrum

Recommended Posts

Hi guys -

 

I know that someone here can help me :-)

 

I need to use an image as a submit button - this image is the result of a php if statement -

 

my current code is below - I need to swap out the value="x" for the result of the php if - any ideas guys ?

 

AikenD

 

<form id="Assign_<?php echo $Contact ?>" action="Assign.php" method="post">

<input type="hidden" name="search" value="<?php echo $search; ?>">

<td>

<?php

if($selected == 'X') {

?>

<img src="images/checked.gif">

<?php

}else{

?>

<img src="images/unchecked.gif"> 

<?php

}

?>

</td>

<td> <input type ="submit" name="assign" value="x">

</td>

</form>

Link to comment
https://forums.phpfreaks.com/topic/52947-using-an-img-src-in-php/
Share on other sites

the result ?

 

results of what ?

 

try

{$_POST['search']}

 

<?php
echo '<td> <input type ="submit" name="assign" value="'.$_POST['search'].'">';
?>

 

 

EDIT:

 

whole thing being

<form id="Assign_<?php echo $Contact ?>" action="Assign.php" method="post">
<input type="hidden" name="search" value="<?php echo $search; ?>">
<td>
<?php
if($selected == 'X') {
?>
<img src="images/checked.gif">
<?php
}else{
?>
<img src="images/unchecked.gif">   
<?php
}
?>
</td>
<?php
echo '<td> <input type ="submit" name="assign" value="'.$_POST['search'].'">';
?>
</td>
</form>

I suspect the question is 'depending on the value of $selected, how can I use a different image as the "submit" in my form?'

 

There ya go MadTechie. Try that one :)

 

 

Cheers Andy

 

in which case i would probably do this

<form id="Assign_<?php echo $Contact ?>" action="Assign.php" method="post">
<input type="hidden" name="search" value="<?php echo $search; ?>">
<td>
<?php
if($selected == 'X') {
     $image = "images/checked.gif";
}else{
     $image = "images/unchecked.gif";
}
echo "<img src='$image'>";
?>
</td>
<td> <input type ="image" name="assign" src="<?php echo $image;?>">
</td>
</form>

I suspect the question is 'depending on the value of $selected, how can I use a different image as the "submit" in my form?'

 

There ya go MadTechie. Try that one :)

 

 

Cheers Andy

 

in which case i would probably do this

<form id="Assign_<?php echo $Contact ?>" action="Assign.php" method="post">
<input type="hidden" name="search" value="<?php echo $search; ?>">
<td>
<?php
if($selected == 'X') {
     $image = "images/checked.gif";
}else{
     $image = "images/unchecked.gif";
}
echo "<img src='$image'>";
?>
</td>
<td> <input type ="image" name="assign" src="<?php echo $image;?>">
</td>
</form>

 

Exactly - many thanks, but worked it out myself in last 10 minutes - still valuable lesson in learning how to ask a question

 

Cheers guys

 

AikenD

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.