neex1233 Posted June 29, 2009 Share Posted June 29, 2009 I made this script that checks if the user has more than one in a MySQL row, and if they do it displays their eMail. If they don't it tells the user that they don't want it to be shown. Here it is: <? require '/home/username/public_html/folder/config.php'; $username = mysql_real_escape_string($_SESSION['username']); $sql="SELECT * FROM users WHERE username='$username'"; $result=mysql_query($sql) or die(mysql_error()); $rows=mysql_fetch_array($result); $email = $row['email']; $do = 1; function doSmily($msg) //Fix eMail { $msg = str_ireplace('@', ' [AT] ', $word); $msg = str_ireplace('.', ' [DOT] ', $word); return $word; } $s = "$email"; $ne = doSmily($s); if($rows['e'] >= $do){ // Check if user has 2 echo "$ne"; }else{ echo "This user chose not to show their eMail."; } ?> Could you help me fix this? If they have more than one in the 'e' column, instead of displaying the user's email, it just says they dont want to show it. Thanks. Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 29, 2009 Share Posted June 29, 2009 Hmm... The way you explain it, I am not sure what you are checking. When you state "If they have more than one in the 'e' column" do you mean if the VALUE for the record is greater then the number 1 or do you mean if there are more than one record for that user with different values in that column. I will assume the former. In that case I don't see why the condition is not working. Have you tested to see what the values are by using some simple debugging? Add this before the IF statment and see what is returned: echo "do = {$do}; e = {$rows['e']}"; however, your function doSmiley will not work. You are passing it a value into the variable $msg, but then you attempt to modify the variable $word. Corrected: <?php require '/home/username/public_html/folder/config.php'; $username = mysql_real_escape_string($_SESSION['username']); $sql="SELECT * FROM users WHERE username='$username'"; $result=mysql_query($sql) or die(mysql_error()); $rows=mysql_fetch_array($result); $do = 1; echo "do = {$do}; e = {$rows['e']}<br />\n"; function doSmily($msg) //Fix eMail { $search = array('@', '.'); $replace = array(' [AT] ', ' [DOT] '); return str_ireplace($search, $replace, $msg); } if($rows['e'] >= $do) { // Check if user has 2 echo doSmily($row['email']); } else { echo "This user chose not to show their eMail."; } ?> Quote Link to comment Share on other sites More sharing options...
neex1233 Posted June 29, 2009 Author Share Posted June 29, 2009 This is what comes up if I use that code: do = 1; e = 2 This user chose not to show their eMail. Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 30, 2009 Share Posted June 30, 2009 Then there is your answer. The value of 'e' being returned from the database is 2 so the correct result of the condition if($rows['e'] >= $do) is being run. To get the other result youwill need to change the value of $username to that of a record where the value of 'e' is 1 or change the value of an existing record to 1. Quote Link to comment 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.