Tech Support Guy banner
Status
Not open for further replies.
1 - 11 of 11 Posts

· Registered
Joined
·
648 Posts
Discussion Starter · #1 ·
Hey,

I have a problem. I am trying to get a UserTo table from MySQL to ensure that the mail was meant for the reader logged in. To do this i'm using:
PHP:
$result = mysql_query("SELECT * FROM $table WHERE UserTo='$cookie' AND mail_id='$mail_id'") or die ("

Can't execute $sql: " .mysql_error());
$row = mysql_fetch_array($result);
if($row[UserTo]==$cookie) 
{
} 
else 
{
echo "

[B]This isn't your mail![/B]

" .$row[UserTo];
exit;
}
As you can see near the end i've printed the $row[UserTo] variable to see what it outputs. It doesn't give me anything which is why it isn't equal to $cookie.

$cookie works and prints the logged in username. $table and the database connection works too so i'm finding it difficult to assess this problem.

If anybody could point out what i'm doing wrong or what's wrong with this code I would be very grateful.

Thanks!
 

· Registered
Joined
·
15,981 Posts
Ok, your SQL query isn't returning any results. You can
echo "SELECT * FROM $table WHERE UserTo='$cookie' AND mail_id='$mail_id'";
to see what your query is, the error is probably in there.
 

· Registered
Joined
·
648 Posts
Discussion Starter · #7 ·
The original line didn't have the ' around $mail_id but that brings up the error
Can't execute : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Heres what I tried with the edited one:

Code:
echo mysql_query("SELECT * FROM $table WHERE UserTo='$cookie' AND mail_id='$mail_id'");
Brings up: Resource id #17

Code:
echo "SELECT * FROM $table WHERE UserTo='$cookie' AND mail_id='$mail_id'";
Brings up: SELECT * FROM mail WHERE UserTo='MyUsername' AND mail_id=''
 

· Registered
Joined
·
648 Posts
Discussion Starter · #9 ·
It isn't....

The strange this is that the ID is stored to get to this part anyway. For example this works:
PHP:
$result=mysql_query("select * from $table where UserTo='$cookie' ORDER BY SentDate DESC") or die ("ERROR: PLEASE REPORT THIS");
echo "[TABLE]";
while ($row=mysql_fetch_array($result)) {
echo "[TR][TD]

Mail:[/TD][TD][URL]
$row[Subject]
[/URL][/TD][TD] [URL]
[CENTER]Delete
[/URL]
[/TD][/TR]";
I'm trying to follow this tutorial (http://www.obsidweb.net/v2/print.php?tutid=2&code=yes&gfx=)

If I can find an alternative way of getting the mail id I can probably get this to work...
 
1 - 11 of 11 Posts
Status
Not open for further replies.
Top