Jump to content

[SOLVED] PHP MySQL Show Script Not Working


neex1233

Recommended Posts

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.

Link to comment
Share on other sites

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.";
}

?>

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.