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> Quote Link to comment 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();" Quote Link to comment 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 /> Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.