wtfsmd Posted January 19, 2007 Share Posted January 19, 2007 I am trying to make it so when you select the radio for the appropriate image it will save that to my database. (here is a screen shot of what im talking about) [url=http://tinypic.com/400xzk5.png]http://tinypic.com/400xzk5.png[/url]The way i had it set up before was type in the whole html code for implementing a picture in a text line.one way that i have tryed this was puting the html code for the image into the value="".and the last way i have tryed it was useing it this way.[code]<?php $pvp = "<img src='./images/instance/pvp.gif'/>"; $alert = "<img src='./images/instance/alert.gif'/>"; $bc = "<img src='./images/instance/bc.gif'/>"; $aq20 = "<img src='./images/instance/aq20.gif'/>"; $aq40 = "<img src='./images/instance/aq40.gif'/>"; $bwl = "<img src='./images/instance/bwl.gif'/>"; $mc = "<img src='./images/instance/mc.gif'/>"; $nax = "<img src='./images/instance/nax.gif'/>"; $onx = "<img src='./images/instance/onx.gif'/>"; $zg = "<img src='./images/instance/zg.gif'/>"; echo '<div align="center"><input type="radio" name="pic" value="$pvp" /></td><td>'; echo '<div align="center"><input type="radio" name="pic" value="$alert" /></td><td>'; echo '<div align="center"><input type="radio" name="pic" value="$bc" /></td><td>'; echo '<div align="center"><input type="radio" name="pic" value="$aq20" /></td><td>'; echo '<div align="center"><input type="radio" name="pic" value="$aq40" /></td><td>'; echo '<div align="center"><input type="radio" name="pic" value="$bwl" /></td><td>'; echo '<div align="center"><input type="radio" name="pic" value="$mc" /></td><td>'; echo '<div align="center"><input type="radio" name="pic" value="$nax" /></td><td>'; echo '<div align="center"><input type="radio" name="pic" value="$onx" /></td><td>'; echo '<div align="center"><input type="radio" name="pic" value="$zg" /></td></tr>';echo '</table>';[/code]all that displays on the page where the article is for the pic is $zg(or what ever you click)i have ran out of ideas on how to do this, could anyone please help me?Thanks.Edit: here is the code for the whole page[code]<?php//Start newsif (isset($_POST['submit'])) { // if form has been submitted $timestamp = date('m d, Y'); $datestamp = date('g:i a');//Pictureif( mysql_query("INSERT INTO news (title, news, pic, timestamp, postby) VALUES('".$_POST['title']."', '".$_POST['news']."', '".$_POST['pic']."', '$timestamp <br> $datestamp', '".$_SESSION['username']."')") or die(mysql_error());} if($_SESSION['level'] == "2") {?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <br><input type="text" name="title" maxlength="40"> - title <br> <table width="40%" border="0"> <tr> <th width="7" scope="col"><img src="./images/instance/pvp.gif"/></th> <th width="7%" scope="col"><img src="./images/instance/alert.gif"/></th> <th width="7%" scope="col"><img src="./images/instance/bc.gif"/></th> <th width="7%" scope="col"><img src="./images/instance/aq20.gif"/></th> <th width="7%" scope="col"><img src="./images/instance/aq40.gif"/></th> <th width="7%" scope="col"><img src="./images/instance/bwl.gif"/></th> <th width="7%" scope="col"><img src="./images/instance/mc.gif"/></th> <th width="7%" scope="col"><img src="./images/instance/nax.gif"/></th> <th width="7%" scope="col"><img src="./images/instance/onx.gif"/></th> <th width="7%" scope="col"><img src="./images/instance/zg.gif"/></th> </tr> <tr> <td> <?php $pvp = "<img src='./images/instance/pvp.gif'/>"; $alert = "<img src='./images/instance/alert.gif'/>"; $bc = "<img src='./images/instance/bc.gif'/>"; $aq20 = "<img src='./images/instance/aq20.gif'/>"; $aq40 = "<img src='./images/instance/aq40.gif'/>"; $bwl = "<img src='./images/instance/bwl.gif'/>"; $mc = "<img src='./images/instance/mc.gif'/>"; $nax = "<img src='./images/instance/nax.gif'/>"; $onx = "<img src='./images/instance/onx.gif'/>"; $zg = "<img src='./images/instance/zg.gif'/>"; echo '<div align="center"><input type="radio" name="pic" value="$pvp" /></td><td>'; echo '<div align="center"><input type="radio" name="pic" value="$alert" /></td><td>'; echo '<div align="center"><input type="radio" name="pic" value="$bc" /></td><td>'; echo '<div align="center"><input type="radio" name="pic" value="$aq20" /></td><td>'; echo '<div align="center"><input type="radio" name="pic" value="$aq40" /></td><td>'; echo '<div align="center"><input type="radio" name="pic" value="$bwl" /></td><td>'; echo '<div align="center"><input type="radio" name="pic" value="$mc" /></td><td>'; echo '<div align="center"><input type="radio" name="pic" value="$nax" /></td><td>'; echo '<div align="center"><input type="radio" name="pic" value="$onx" /></td><td>'; echo '<div align="center"><input type="radio" name="pic" value="$zg" /></td></tr>';echo '</table>';?> <textarea cols="63" name="news" rows="10" value="Type here"></textarea><br><input type="submit" name="submit" method="post" value="Post News"> </body> </html><?php}else{ echo '<h2>You need to be an Admin to access the Control Panel.</h2>';}?>[/code] Quote Link to comment Share on other sites More sharing options...
Braclayrab Posted January 19, 2007 Share Posted January 19, 2007 Well, your way would work, I believe. However, you can't have a '>' char in the middle of an attribute on the img element. Do you really need the full html of the image? Just use the source and save that to your DB.$bwl = "./images/instance/bwl.gif"You might also consider writing some javascript to handle this. Perhaps put a hidden input on your form and then when someone clicks on a radiobutton you can use the onClick event to populate the hidden input. You would then store the data in a javascript library object rather than in the values of your radiobuttons themselves and only put the indexes in the values of the radiobuttons. Just a suggestion, this is more for style than correctness. Also, I don't see a </form>, am I just not seeing it? Quote Link to comment Share on other sites More sharing options...
wtfsmd Posted January 19, 2007 Author Share Posted January 19, 2007 yeah forgot i deleted the </form> on accident but it made no difference, the way i have it now with the $pvp = <img src ... is it puts the value of the checkbox (value='$pvp') into the page where it is outputed as $pvp instead of the image, thats why it didnt work. but i like your idea about the javascript. Quote Link to comment Share on other sites More sharing options...
wtfsmd Posted January 19, 2007 Author Share Posted January 19, 2007 ah you gave me an idea and i figured out a way to do it Quote Link to comment Share on other sites More sharing options...
wtfsmd Posted January 19, 2007 Author Share Posted January 19, 2007 i did it this way:[code]<?php echo '<div align="center"><input type="radio" name="pic" value="./images/instance/pvp.gif" /></td><td>'; echo '<div align="center"><input type="radio" name="pic" value="./images/instance/alert.gif" /></td><td>'; echo '<div align="center"><input type="radio" name="pic" value="./images/instance/bc.gif" /></td><td>'; echo '<div align="center"><input type="radio" name="pic" value="./images/instance/aq20.gif" /></td><td>'; echo '<div align="center"><input type="radio" name="pic" value="./images/instance/aq40.gif" /></td><td>'; echo '<div align="center"><input type="radio" name="pic" value="./images/instance/bwl.gif" /></td><td>'; echo '<div align="center"><input type="radio" name="pic" value="./images/instance/mc.gif" /></td><td>'; echo '<div align="center"><input type="radio" name="pic" value="./images/instance/nax.gif" /></td><td>'; echo '<div align="center"><input type="radio" name="pic" value="./images/instance/onx.gif" /></td><td>'; echo '<div align="center"><input type="radio" name="pic" value="./images/instance/zg.gif" /></td></tr>';[/code]without the html code.and on the page that outputs it i used this:[code]echo "<th><img src='"; echo $row['pic']; echo "'/></th>";[/code]put the html code around where the info would be outputted. Quote Link to comment Share on other sites More sharing options...
Braclayrab Posted January 19, 2007 Share Posted January 19, 2007 cool, glad I could help. You could also go one step further and drop all the php outta there:<div align="center"><input type="radio" name="pic" value="./images/instance/pvp.gif" /><div align="center"><input type="radio" name="pic" value="./images/instance/alert.gif" /><div align="center"><input type="radio" name="pic" value="./images/instance/bc.gif" /><div align="center"><input type="radio" name="pic" value="./images/instance/aq20.gif" /><div align="center"><input type="radio" name="pic" value="./images/instance/aq40.gif" />etc.I won't ask about the random td's. >.< 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.