Page 1 of 1
MySQL/PHP Script Error
Posted: Mon Jun 29, 2009 7:34 pm
by neex1233
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:
Code: Select all
<?
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.
Re: MySQL/PHP Script Error
Posted: Mon Jun 29, 2009 8:09 pm
by BornForCode
I assume that in the specified table you have only one record per user, the code is:
Code: Select all
<?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;
Re: MySQL/PHP Script Error
Posted: Mon Jun 29, 2009 9:45 pm
by neex1233
That still doesn't work.
Re: MySQL/PHP Script Error
Posted: Mon Jun 29, 2009 10:16 pm
by Eric!
Can you be more descriptive than does not work? I found several problems with the code. Also insert
at line 19 for debugging and see what is there.
Line 8 should be:
Code: Select all
$email = $rows['email']; // rows not row
Your function should be
Code: Select all
function doSmily($msg) //Fix eMail
{
$msg = str_ireplace('@', ' [AT] ', $msg);
$msg = str_ireplace('.', ' [DOT] ', $msg);
return $msg;
}
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.
Re: MySQL/PHP Script Error
Posted: Tue Jun 30, 2009 10:33 am
by neex1233
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
But this is the final code:
Code: Select all
<?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";
$ee = $rows['email'];
function doSmily($msg) //Fix eMail
{
$msg = str_ireplace('@', ' [AT] ', $msg);
$msg = str_ireplace('.', ' [DOT] ', $msg);
return $msg;
}
if($rows['e'] >= $do)
echo $rows['e'];
{ // Check if user has 2
echo doSmily($row['email']);
}
else
{
echo "This user chose not to show their eMail.";
}
?>
Re: MySQL/PHP Script Error
Posted: Tue Jun 30, 2009 10:41 am
by BornForCode
I updated the code, check it out.
Re: MySQL/PHP Script Error
Posted: Tue Jun 30, 2009 10:42 am
by neex1233
Which code?
Re: MySQL/PHP Script Error
Posted: Tue Jun 30, 2009 10:44 am
by BornForCode
The code from my post

Re: MySQL/PHP Script Error
Posted: Tue Jun 30, 2009 10:45 am
by neex1233
Okay, well even though the user has more than one, I get this:
This user chose not to show their eMail
Re: MySQL/PHP Script Error
Posted: Tue Jun 30, 2009 10:50 am
by BornForCode
Are you sure that the value of $row['e'] is greater than 0?
Can you check please by putting an echo to it somewhere at the end of the code.
Re: MySQL/PHP Script Error
Posted: Tue Jun 30, 2009 11:00 am
by neex1233
I am.
Re: MySQL/PHP Script Error
Posted: Tue Jun 30, 2009 11:03 am
by BornForCode
Does the guys from devenet charging the posts based on the number of words used?

Re: MySQL/PHP Script Error
Posted: Tue Jun 30, 2009 11:13 am
by neex1233
What???
Re: MySQL/PHP Script Error
Posted: Tue Jun 30, 2009 1:35 pm
by Eric!
You put the echo debug statement in the wrong place. And BornForCode's code still has the $word bug in it.
Try this:
Code: Select all
<?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";
$ee = $rows['email'];
function doSmily($msg) //Fix eMail
{
$msg = str_ireplace('@', ' [AT] ', $msg);
$msg = str_ireplace('.', ' [DOT] ', $msg);
return $msg;
}
echo "This is rows e: ".$rows['e']; // for debugging only
if($rows['e'] >= $do)
{ // Check if user has 2
echo doSmily($row['email']);
}
else
{
echo "This user chose not to show their eMail.";
}
?>
Re: MySQL/PHP Script Error
Posted: Wed Jul 01, 2009 9:44 am
by BornForCode
Nooo i've fixed that
