herghost Posted May 25, 2011 Share Posted May 25, 2011 Hi all, I have this: <?php session_start(); include('login/functions.php'); $username = $_SESSION['username']; $check = mysql_query("SELECT email FROM user_profile WHERE username = '$username'"); $a = mysql_fetch_field($check); if(empty($a)) { header('Location: complete.php'); } ?> However if the field is empty, ie no email address for user then nothing happens? Am going about this the right way? Cheers Quote Link to comment https://forums.phpfreaks.com/topic/237378-if-field-is-empty-help/ Share on other sites More sharing options...
xyph Posted May 25, 2011 Share Posted May 25, 2011 You want to use mysql_num_rows() for this Quote Link to comment https://forums.phpfreaks.com/topic/237378-if-field-is-empty-help/#findComment-1219803 Share on other sites More sharing options...
herghost Posted May 25, 2011 Author Share Posted May 25, 2011 Same problem The row itself will exist, as its created on first login (twitter oauth) However on first login email will not be filled in the row. I have <?php session_start(); include('login/functions.php'); $username = $_SESSION['username']; $check = mysql_query("SELECT email FROM user_profile WHERE username = '$username'"); $a = mysql_num_rows($check); if(!$check) { echo mysql_error(); } if(empty($a)) { header('Location: complete.php'); } ?> The query doesnt fail so its not that Quote Link to comment https://forums.phpfreaks.com/topic/237378-if-field-is-empty-help/#findComment-1219805 Share on other sites More sharing options...
xyph Posted May 25, 2011 Share Posted May 25, 2011 Oh, i see what you're doing now. mysql_fetch_field will return an object, so empty might not trigger. TRy mysql_result($check, 0) Quote Link to comment https://forums.phpfreaks.com/topic/237378-if-field-is-empty-help/#findComment-1219810 Share on other sites More sharing options...
herghost Posted May 25, 2011 Author Share Posted May 25, 2011 Perfect! Thanks:) <?php session_start(); include('login/functions.php'); $username = $_SESSION['username']; $check = mysql_query("SELECT email FROM user_profile WHERE username = '$username'"); $num = mysql_result($check, 0); if(empty($num)) { header('location: complete.php'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/237378-if-field-is-empty-help/#findComment-1219811 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.