zelig Posted November 22, 2011 Share Posted November 22, 2011 Okay, so I'm trying to run a query to pull the information from a specific item that they click on in order to edit it. When I run an echo $query, though, it shows the field names rather than the information from the table. How can I make it so that it pulls the information rather than the field names? Here's what I have... <?php include("lib.php"); define("PAGENAME", "Edit Equipment"); if ($player->access < 100) $msg1 = "<font color=\"red\">"; //name error? $error = 0; $query = $db->execute("SELECT * FROM items WHERE id=?", array($_POST['id'])); echo "$id"; $result = mysql_query($query); echo "$query"; $data = mysql_fetch_assoc($result); $msg1 .= "</font>"; //name error? ?> Thanks!! Quote Link to comment https://forums.phpfreaks.com/topic/251589-not-pulling-data-from-table-just-field-names/ Share on other sites More sharing options...
MasterACE14 Posted November 22, 2011 Share Posted November 22, 2011 I don't see you echo'ing any data. Need to add... echo $data['column_name']; after... $data = mysql_fetch_assoc($result); Quote Link to comment https://forums.phpfreaks.com/topic/251589-not-pulling-data-from-table-just-field-names/#findComment-1290270 Share on other sites More sharing options...
zelig Posted November 22, 2011 Author Share Posted November 22, 2011 I threw the echo $data in there after the $data query, but still getting the same error: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in edit_equipment.php on line 19 Quote Link to comment https://forums.phpfreaks.com/topic/251589-not-pulling-data-from-table-just-field-names/#findComment-1290442 Share on other sites More sharing options...
ManiacDan Posted November 22, 2011 Share Posted November 22, 2011 You're mixing usage of $db with the base mysql functions. One or the other. $db->execute() returns a result object meant to be used however the $db library is designed (you don't say what you're using). You cannot pass a result object back through the query function, the query function expects a string and will return false when you give it an object. Then, you take that false and pass it into the fetch function, which throws the error you posted (which should have been in your first post). Quote Link to comment https://forums.phpfreaks.com/topic/251589-not-pulling-data-from-table-just-field-names/#findComment-1290487 Share on other sites More sharing options...
ManiacDan Posted November 22, 2011 Share Posted November 22, 2011 There were three messages here about someone posting in this thread by mistake, they've been removed so it's not so confusing. Carry on. Quote Link to comment https://forums.phpfreaks.com/topic/251589-not-pulling-data-from-table-just-field-names/#findComment-1290517 Share on other sites More sharing options...
jcbones Posted November 22, 2011 Share Posted November 22, 2011 The only db class that I know of that uses a "execute" method, returns "mysql_affected_rows()". This method is suppose to be used for "INSERT, UPDATES, DELETES" according to the documentation in the class. There is also a "query" method, that returns a resource, of which the method "fetchNextObject()" will return (ironically) a data object. DB class Although, the more powerful PDO should be used instead of this class. Quote Link to comment https://forums.phpfreaks.com/topic/251589-not-pulling-data-from-table-just-field-names/#findComment-1290604 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.