bassguru Posted July 20, 2009 Share Posted July 20, 2009 Hello everyone, got a problem with mysql_query... I'm attempting to get the value 'admin' from the table (value will either be a 'y' or 'n', as in yes or no to admin priviledges). The problem is, I want to store the query as the variable '$admin'. I have no idea how to store the query as a variable and not an array, as all the example I have seen of mysql_query save the query to an array then use a while loop to echo the results into a table! Below is the code I have been working on: $admin = mysql_query("SELECT admin FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error()); Quite simple really; the query selects the admin value ('y' or 'n') where the username matches the username submitted from the form. I DO NOT want to output the result into a table!! The query itself will only return a single value and that value will be stored in a cookie. So the rest of the code will look like this: setcookie(Admin_my_site, $admin, $hour); Please help me! I've been stuck for days! Many thanks in advance Bassguru Link to comment https://forums.phpfreaks.com/topic/166706-solved-mysql_query-help/ Share on other sites More sharing options...
jjacquay712 Posted July 20, 2009 Share Posted July 20, 2009 I can show you how to do it, but having that cookie makes it very extremely insecure. People could manually edit the cookie to say "y". You should use php sessions instead. Anyway, here is the code to do what you want: <?php $admin = mysql_query("SELECT admin FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error()); $admin = mysql_fetch_array($admin); $admin = $admin['admin']; ?> Link to comment https://forums.phpfreaks.com/topic/166706-solved-mysql_query-help/#findComment-879041 Share on other sites More sharing options...
bassguru Posted July 20, 2009 Author Share Posted July 20, 2009 Thank you very much jjacquary712! Yes the cookie does leave my site vulnerable. To change that I think I'll alter the 'y' or 'n' to jiberish (such as 'wkjf12k') then use MD5 to encrypt the cookie... should make it slightly more secure than an incredable obvious Admin_my_site/y/! Thanks again! Bassguru Link to comment https://forums.phpfreaks.com/topic/166706-solved-mysql_query-help/#findComment-879048 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.