jasonxxx102 Posted February 7, 2014 Share Posted February 7, 2014 Ok, so I have a main page that grabs data from a MySQL db and posts it into a dropdown menu see here: $sql = "SELECT * FROM 4000Series"; $result = $con->query($sql); print "Select your GPU: <select name='gpuId'>"; while ($row = $result->fetch_assoc()) { print "<option value='" .$row["id"] . "'>" . $row["gpu"] . "</option>"; } print "</select> </br>\n"; This works fine, from here I'm passing the POST data from the option values to a new page (basically the option values correspond directly to the "id" value in my SQL db). The values are passed onto the new page fine, but when I try to setup an SQL select statement to grab the row with the corresponding "id" value and print it out with a while loop I'm shooting a blank. Here's the code for the second page $id = $_POST['gpuId']; **Connect to sql db here** $sql = "SELECT * FROM 4000Series WHERE $id ='id'"; $result = $con->query($sql); echo "<table>"; while ($row = $result->fetch_assoc()){ echo "<tr><td>" . $row['id'] . "</td><td>" . $row['gpu'] . "</td></tr>"; } echo "</table>"; When I view the source it prints out the table tags but nothing in the while loop, any ideas? Quote Link to comment Share on other sites More sharing options...
denno020 Posted February 7, 2014 Share Posted February 7, 2014 Don't you have to call execute() on $con? I don't know what $con is so I don't know what method you're using.. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted February 7, 2014 Share Posted February 7, 2014 (edited) you have a $ in front of your id column name in your query, you are also missing the $ in front of the $id variable name in your query OR you could remove the single-quotes from around the id column name in your query. if you include a debugging step where you echo out your sql query statement, you would have likely seen this problem. Edited February 7, 2014 by mac_gyver Quote Link to comment Share on other sites More sharing options...
Solution jasonxxx102 Posted February 8, 2014 Author Solution Share Posted February 8, 2014 Thanks mac_gyver! your help was much appreciated 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.