PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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.";
}
?>
If they have more than one in the 'e' column (in the MySQL DB), instead of displaying the user's email, it just says they dont want to show it. Could you help me fix this? Thanks.
<?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());
// One record is supposed to be returned
$row=mysql_fetch_assoc($result);
$do = 1;
function doSmily($msg) //Fix eMail
{
$msg = str_ireplace('@', ' [AT] ', $word);
$msg = str_ireplace('.', ' [DOT] ', $word);
return $msg;
}
// If he has more then an address
$message = ($row['e'] >= $do)? doSmily($row['email']) : 'This user chose not to show their eMail';
echo $message;
Last edited by BornForCode on Tue Jun 30, 2009 10:42 am, edited 3 times in total.
Without more information about your problem that is the best I can do. Most likely the problem is your function was returning $word which is an undefined value and you were trying to echo it as an email address.
By not working I mean that even if the user has more than one in the e column, it says that they chose not to show their email. Also, if I use that code, I get this error:
Parse error: syntax error, unexpected T_ELSE in /home/username/public_html/folder/folder/e.php on line 22