esoteric Posted September 23, 2011 Share Posted September 23, 2011 Hi guys, im trying to connect to a database and get the value for the user in the row called 'user_credit', if it equals 1 or more then i want to show the ''You have £ ....'' bit in the script. Problem is nothing shows at all, even without the if statement. I have changed the value for me in the database so in user_credit the value is 100, which is more than 1 so it should appear. I have probably done something wrong. Any ideas? <? include '../admin/database/membership_dbc.php'; $r = mysql_query("SELECT * FROM users WHERE user_name='".safe($_SESSION['user_name'])."'") or die ("Cannot find table"); while( $cred = mysql_fetch_array($r) ) { if ($cred >= '1' ) { ?> <p>You have £<? echo $cred['user_credit']; ?> available on you account, would you like to use it on this order?<br> <label for="credit"></label> <select name="credit" id="credit"> <option value="Y" selected>Yes, use credit</option> <option value="N">No, save credit</option> </select> </p> <? } } ?> Link to comment https://forums.phpfreaks.com/topic/247734-db-query-wont-return-data/ Share on other sites More sharing options...
WebStyles Posted September 23, 2011 Share Posted September 23, 2011 what is that safe() function you're calling? turn on your error reporting and post the error you're getting please. Link to comment https://forums.phpfreaks.com/topic/247734-db-query-wont-return-data/#findComment-1272161 Share on other sites More sharing options...
DavidAM Posted September 23, 2011 Share Posted September 23, 2011 mysql_fetch_array returns an array of data representing each row selected. So your code: while( $cred = mysql_fetch_array($r) ) { if ($cred >= '1' ) is not correct. $cred is an array and the if test will never be true. Looking at the rest of your code, you should probably using: if ($cred['user_credit'] >= 1) The user_credit column really should be numeric so you don't need to use the quotes around the number 1. Link to comment https://forums.phpfreaks.com/topic/247734-db-query-wont-return-data/#findComment-1272163 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.