dartfrogs Posted July 13, 2008 Share Posted July 13, 2008 I am retrieving data from a mysql table and I am using the image with an onclik attribute to submit the information from the records retrieved. When I echo the post value of the record click it always comes back as the value of the last record retrieved from the table. here is the code. <?php session_start(); include ("battlegear.php"); include("lib/io.lib.php"); $title .= ' <table width="100%"><tr><td align="center"><font color="red">Welcome To</font></td></tr></table>'; $footercontent .= '<table class="bd" width="100%"><tr><td class="hr">Battlegear Toys</td></tr></table>'; $conn = connect(); $flags = Getflags(); $category = Getcategories(); $newitem = GetNewItems(); ///this is the value I need passed to the other page... echo $cid = $_POST['xcid']; This is the function I am using to get the records from mysql and I am using an image with the onclick to submit the info. to test to see if I get the right value to pass I have echoed the value back to the same page but it keeps coming up with the value of the last record. I am not sure where I am going wrong or if this is even the right way to try this. function Getflags() { $res = sql_select_country(); $flags = '<form action="index.php" method="post"><table>'; while($resultset = @mysql_fetch_array($res)) { $id = $resultset['id']; $country=$resultset['country_name']; $flag=$resultset['flag_image']; $flags .=' <tr> <td><input type="hidden" name="xcid" value="'.$id.'" />'. $country .'</td> <td><input type="image" src="'. $flag .'" onclick="javascript:this.form.submit()"/></td> <td></td> </tr> '; $i += 1; } $flags .=' </table></form>'; mysql_free_result($res); return $flags; } function sql_select_country() { global $conn; $sql = "SELECT `id`, `country_name`, `flag_image` FROM `country`"; $res = mysql_query($sql, $conn) or die(mysql_error()); return $res; } function connect() { $conn = mysql_connect("localhost", "root", "raccoon+eyes"); mysql_select_db("battlegear_inventory"); return $conn; } // stuff strings into template and return html string echo use_template("templates/page.html", array("#content#","#title#", "#flags#", "#footercontent#", "#category#", "#newitem#"), array($content, $title, $flags, $footercontent, $category, $newitem)); ?> I have placed the code on the internet the link is http://www.magnetic-webdesign.com/newsite/index.php When you click on a country flag image it is suppose to pass the id value through to the next page but as you can see it only passes the last id value of the last record. I hope this is making sense to you all. Any help I can get to fix this would be great. Quote Link to comment Share on other sites More sharing options...
teynon Posted July 13, 2008 Share Posted July 13, 2008 Use $_GET['xcid'] and put this on the end of your flags... display.php?xcid=$var Quote Link to comment Share on other sites More sharing options...
dartfrogs Posted July 13, 2008 Author Share Posted July 13, 2008 this did not help because I am getting a value just getting the wrong value. I need to gett eh value for the record not the value for the last record every single time. I thank you for the sugestion I did change the other end to $_GET. Quote Link to comment Share on other sites More sharing options...
dartfrogs Posted July 14, 2008 Author Share Posted July 14, 2008 I figured out the problem... Yippee! function Getflags() { $res = sql_select_country(); $cid = $_POST['flag']; $flags = '<form action="display.php" method="post"><table>'; while($resultset = @mysql_fetch_array($res)) { $id = $resultset['id']; $country=$resultset['country_name']; $flag=$resultset['flag_image']; $flags .=' <tr> <td>'. $country .'</td> <td><input type="image" src="'. $flag .'" name="flag" value="'.$id.'" onclick="javascript:this.form.submit()"/></td> <td></td> </tr> '; //$i += 1; } $flags .=' </table></form>'; mysql_free_result($res); return $flags; } You can see where I made the changes and it works... 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.