bindiya Posted December 28, 2010 Share Posted December 28, 2010 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 https://forums.phpfreaks.com/topic/222797-to-dispaly-an-image-on-selecting-the-item-from-the-select-box/ Share on other sites More sharing options...
dragon_sa Posted December 28, 2010 Share Posted December 28, 2010 change onChange="this.form.submit();" to onChange="document.abc.submit();" Link to comment https://forums.phpfreaks.com/topic/222797-to-dispaly-an-image-on-selecting-the-item-from-the-select-box/#findComment-1152049 Share on other sites More sharing options...
dragon_sa Posted December 28, 2010 Share Posted December 28, 2010 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 https://forums.phpfreaks.com/topic/222797-to-dispaly-an-image-on-selecting-the-item-from-the-select-box/#findComment-1152055 Share on other sites More sharing options...
bindiya Posted December 29, 2010 Author Share Posted December 29, 2010 dear dragon_sa, i have used the same code u provided.But the image doesnot show when i change the contents in the select button. Link to comment https://forums.phpfreaks.com/topic/222797-to-dispaly-an-image-on-selecting-the-item-from-the-select-box/#findComment-1152426 Share on other sites More sharing options...
dragon_sa Posted December 29, 2010 Share Posted December 29, 2010 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 https://forums.phpfreaks.com/topic/222797-to-dispaly-an-image-on-selecting-the-item-from-the-select-box/#findComment-1152436 Share on other sites More sharing options...
bindiya Posted January 8, 2011 Author Share Posted January 8, 2011 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 https://forums.phpfreaks.com/topic/222797-to-dispaly-an-image-on-selecting-the-item-from-the-select-box/#findComment-1156549 Share on other sites More sharing options...
Pikachu2000 Posted January 8, 2011 Share Posted January 8, 2011 When posting code, please post it within . . . BBCode tags. Link to comment https://forums.phpfreaks.com/topic/222797-to-dispaly-an-image-on-selecting-the-item-from-the-select-box/#findComment-1156550 Share on other sites More sharing options...
bindiya Posted January 8, 2011 Author Share Posted January 8, 2011 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 https://forums.phpfreaks.com/topic/222797-to-dispaly-an-image-on-selecting-the-item-from-the-select-box/#findComment-1156569 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.