fife Posted November 29, 2011 Share Posted November 29, 2011 Hi. I have an ID in md5 format but in the database its not. I pass the md5 ID to a page and then I am trying to load the correct record via a look up in the database of that ID. Im wondering is this code possible? <?php $query = mysql_query("SELECT * FROM table WHERE ".md5(tableID)." = $ID"); ?> Thanks Link to comment https://forums.phpfreaks.com/topic/252026-simple-md5-question/ Share on other sites More sharing options...
Pikachu2000 Posted November 29, 2011 Share Posted November 29, 2011 What happened when you tried it? Link to comment https://forums.phpfreaks.com/topic/252026-simple-md5-question/#findComment-1292155 Share on other sites More sharing options...
fife Posted November 29, 2011 Author Share Posted November 29, 2011 Sorry for late reply guys. Im in work. Yes when I ran the query I had this error..... Unknown column '8244100d2bc069d6d4c6e3d8f984c6de' in 'where clause' Link to comment https://forums.phpfreaks.com/topic/252026-simple-md5-question/#findComment-1292296 Share on other sites More sharing options...
xyph Posted November 29, 2011 Share Posted November 29, 2011 No. MD5 is a one-way hash. You can't get the ID back from the hash without a look-up table Link to comment https://forums.phpfreaks.com/topic/252026-simple-md5-question/#findComment-1292298 Share on other sites More sharing options...
fife Posted November 29, 2011 Author Share Posted November 29, 2011 so this is not possible then as the ID in the data base is not in md5? <?php $ID = md5($ID); $query = mysql_query("SELECT * FROM table WHERE ".md5(tableID)." = $ID"); ?> Link to comment https://forums.phpfreaks.com/topic/252026-simple-md5-question/#findComment-1292300 Share on other sites More sharing options...
PFMaBiSmAd Posted November 29, 2011 Share Posted November 29, 2011 If $ID is an md5 value, it is a string and needs to be enclosed in single-quotes in the query statement. If tableID is a column in your table, you cannot use php's md5() function on the value, you must use mysql's md5 function on the value inside the query statement. $query = mysql_query("SELECT * FROM table WHERE md5(tableID) = '$ID'"); Link to comment https://forums.phpfreaks.com/topic/252026-simple-md5-question/#findComment-1292301 Share on other sites More sharing options...
xyph Posted November 29, 2011 Share Posted November 29, 2011 That query will cause MySQL to perform an MD5 on every row in your table. This is generally a very bad idea. That is how you'd want to form your query though. Link to comment https://forums.phpfreaks.com/topic/252026-simple-md5-question/#findComment-1292302 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.