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>

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.