Jump to content

to dispaly an image on selecting the item from the select box


bindiya

Recommended Posts

In my php site i have a select button.On selecting an item from the select box ,the corresponding picture should be displayed in the <img>,from the mysql database.

This is not happening with the following code

 

 

<form name='abc' method='post'>

<select name="std_name" onChange="this.form.submit();">

<option value="...Select...">...Select...</option>

<option value="Adam">Adam </option>

<option value="Amanda">Amanda</option>

<option value="Angel">Angel </option>

<option value="Brewier">Brewier</option>

<option value="Butle">Butler </option>

<option value="Carrie">Carrie </option>

</select><br />

<?php

if(isset($_POST['submit']))

{

 

$aname1=$_POST['std_name'];

 

$sql1="select * from std where name='$aname1'";

$result=mysql_query($sql1);

while($n=mysql_fetch_row($result))

{

echo $n[2];

echo "<img src='$n[2]' width='118' height='133' name='std/>";}

}

?>

<img src="Adam.jpg" width="118" height="133" name="std"/><br />

 

 

 

</form>

 

also a few other things I just noticed

 

<?php
if (isset($_POST['std_name'])) {
$aname1=$_POST['std_name'];
//include database connection
    include('db_connect.php');
$sql1="select * from std where name='$aname1'";
$result=mysql_query($sql1);
$n=mysql_fetch_row($result);
$img=$n['2']; // assuming 2 is the name of your image column in the database
}
?>

<form name='abc' method='post' action=''>
<select name="std_name" onChange="document.abc.submit();">
<option value="...Select...">...Select...</option>
<option value="Adam">Adam </option>
<option value="Amanda">Amanda</option>
<option value="Angel">Angel </option>
<option value="Brewier">Brewier</option>
<option value="Butle">Butler </option>
<option value="Carrie">Carrie </option>
</select><br />
<?php if (isset($img) && $img!='') { echo "<img src=' $img;' width='118' height='133' name='std' /><br/>"; ?>
<img src="Adam.jpg" width="118" height="133" name="std"/><br />

hi

The code also needs to be in that order with the php at the top and you select form underneath it

 

I also made a small typo change

<img src=' $img;' width='118' height='133' name='std' /><br/>

to

<img src='$img' width='118' height='133' name='std' /><br/>

 

also for that to work the image would have to be in the same directory as the file running this code, if not you need to specify which directory the images are in.

 

If it is still not working echo $img and see what it gives you

  • 2 weeks later...

the problem i am facing is

1)The form has many input tags and select buttons and radio buttons

2)i have a javascript that validates the form,when the form is submitted.

 

So when i use the following code

 

<?php

if (isset($_POST['std_name'])) {

$aname1=$_POST['std_name'];

//include database connection

    include('db_connect.php');

$sql1="select * from std where name='$aname1'";

$result=mysql_query($sql1);

$n=mysql_fetch_row($result);

$img=$n['2']; // assuming 2 is the name of your image column in the database

}

?>

 

Code: [select]

<form name='abc' method='post' action=''>

<select name="std_name" onChange="document.abc.submit();">

<option value="...Select...">...Select...</option>

<option value="Adam">Adam </option>

<option value="Amanda">Amanda</option>

<option value="Angel">Angel </option>

<option value="Brewier">Brewier</option>

<option value="Butle">Butler </option>

<option value="Carrie">Carrie </option>

</select><br />

<?php if (isset($img) && $img!='') { echo "<img src=' $img;' width='118' height='133' name='std' /><br/>"; ?>

 

does not work and the image doesnot show.When i click submit the validation js works,so the image doesnot work.

 

how can i resolve this problem?

sorry for posting wronly

pasting the doubt correctly

 

 

the problem i am facing is

1)The form has many input tags and select buttons and radio buttons

2)i have a javascript that validates the form,when the form is submitted.

 

So when i use the following code

<?php
if (isset($_POST['std_name'])) {
$aname1=$_POST['std_name'];
//include database connection
    include('db_connect.php');
$sql1="select * from std where name='$aname1'";
$result=mysql_query($sql1);
$n=mysql_fetch_row($result);
$img=$n['2']; // assuming 2 is the name of your image column in the database
}
?>

<form name='abc' method='post' action=''>
<select name="std_name" onChange="document.abc.submit();">
<option value="...Select...">...Select...</option>
<option value="Adam">Adam </option>
<option value="Amanda">Amanda</option>
<option value="Angel">Angel </option>
<option value="Brewier">Brewier</option>
<option value="Butle">Butler </option>
<option value="Carrie">Carrie </option>
</select><br />
<?php if (isset($img) && $img!='') { echo "<img src=' $img;' width='118' height='133' name='std' /><br/>"; ?>

 

does not work and the image doesnot show.When i click submit the validation js works,so the image doesnot work.

 

how can i resolve this problem?

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.