Page 1 of 2

Need Help, Full Code And Background Provided

Posted: Thu Jan 08, 2004 7:36 am
by malcolmboston
Hi guys,

Im currently having some problems with getting a script to run and im not really too sure why that is tbh

Here is what i want to do.....

I am currently developing a private messaging system which will hopefully, be not to dissimilar to its phpBB
equivalent, now i have actually developed 2, the other works but its features are very limited, on my first one i
could not distinguish between what messages had been read and which had'nt, a couple of other useful features also, unfortunately
i couldnt implement to my satisfaction

the Read_Unread column should work by setting a flag as read on a page as the columns default is Unread so hopefully i can
do this, i cannot really see any downside to doing it this way as it can always be marked as unread if the user wishes

NOW HERES MY PROBLEM

i am having trouble with my database query (i believe)


My Database Connection
SERVER - localhost
USER - malcolmboston
PASSWORD - xxxxxx

The table i am trying to interact with
DATABASE NAME - tees-drug-network
TABLE NAME - private_messaging

Structure Of Table
Recipient
Sender
Subject
Message
Timestamp
Read_Unread

Heres the query

Code: Select all

<?php
$_SESSION['username'] = malcolmboston;
// database variables for connections 
$host = "localhost"; 
$user = "malcolmboston"; 
$password = "xxxxxx"; 
$DBname = "tees-drug-network"; 
$tablename = "private_messaging"; 
//connection variables completed 
// establishing connections 
$link = mysql_connect ($host, $user, $password); 
//connection established 
//the query defined 
$query = "SELECT * FROM $tablename WHERE recipient = '".$_SESSION['username']." AND Read_Unread ==unread'"; 

// select the database 
mysql_select_db($DBname); 
//getting the data
$result = mysql_query($query); 
$data = mysql_fetch_array($result, MYSQL_ASSOC);


//ways of showing the data
//none work
php print $query
<br>
php print $result
<br>
php print $data
<br>
on the above section of code it appears that the actual query syntax is incorrect,
AND Read_Unread ==unread'"
see the extra 'colon' (or whatever its called) now i dont believe that is supposed
to be there, however, when i remove it or add the matching 'colon' it gives me this
mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>PHPDocument3</b> on line <b>20</b><br />
which is this line.......
[qoute]$data = mysql_fetch_array($result, MYSQL_ASSOC);[/quote]
i get this message alot in other scripts (if anyone can tell me why i would be forever in your debt!) i have created but have managed to sort them out, however this is my first time at
trying to do "multi-query" and i am merely guessing at the correct syntax as the mysql manual doesnt list any type of query like
this, only very simple ones not including VARS


Now i know this is only going to show me the actual Unread messages for a user (designated by there session_name meaning only that
person can get there e-mail, ive did this before and it works btw) so i was going to do to 2 queries, one retrieving all messages for the
user and then after that retrieving the unread messages and listing them at the top

This doesnt work, btw but u get the idea

Code: Select all

//number of unread messages or even simpler just to see if there are ANY!
$unread_msgs = result from query
//var is now set
here is the code i have actually wrote on another page and works (mail_redirection.php)

Code: Select all

<?php
if ($unread_msgs >= 1) {
    header ("Location: mail_yes.php");
} else {
    header ("Location: mail_no.php");
    exit;
}
?>
if anyone can tell me where im going wrong it would be greatly appreciated, this is the first time ive been stuck on
a script for a long time now.

if you need anymore info, dont hesitate to ask

thanks

Posted: Thu Jan 08, 2004 7:44 am
by fastfingertips
Look to this
recipient = -> '" <- .$_SESSION['username']."

There to many :) i think that is enough only " you do not need anymore '

Posted: Thu Jan 08, 2004 7:49 am
by malcolmboston
?????

Posted: Thu Jan 08, 2004 7:52 am
by JayBird
.for starters, this line

Code: Select all

$query = "SELECT * FROM $tablename WHERE recipient = '".$_SESSION['username']." AND Read_Unread ==unread'";
Should be

Code: Select all

$query = "SELECT * FROM $tablename WHERE recipient = '".$_SESSION['username']."' AND Read_Unread = 'unread'";
Mark

Posted: Thu Jan 08, 2004 7:52 am
by fastfingertips
SELECT * FROM $tablename WHERE recipient = ".$_SESSION['username']." AND Read_Unread ==unread"

Please use this

Posted: Thu Jan 08, 2004 7:54 am
by jason
Actually, fastfingertips is almost right:

Code: Select all

$query = "SELECT * FROM $tablename WHERE recipient = '".$_SESSION['username']." AND Read_Unread ==unread'";
Look right after $_SESSION['username'], you forget the second '. And for "Read_Unread ==unread'", just change it to this "Read_Unread = 'unread'"

Posted: Thu Jan 08, 2004 7:54 am
by fastfingertips
I think that unread is a mailbox prop

Mailbox properties

Date date of last change
Driver driver
Mailbox name of the mailbox
Nmsgs number of messages
Recent number of recent messages
Unread number of unread messages
Deleted number of deleted messages
Size mailbox size

And may be accessed like this

Code: Select all

&lt;?php
$mbox = imap_open("{your.imap.host}INBOX","username", "password")
      or die("can't connect: ".imap_last_error());
 
$check = imap_mailboxmsginfo($mbox);
 
if($check) {
    print "Date: "    . $check-&gt;Date    ."&lt;br&gt;\n" ;
    print "Driver: "  . $check-&gt;Driver  ."&lt;br&gt;\n" ;
    print "Mailbox: " . $check-&gt;Mailbox ."&lt;br&gt;\n" ;
    print "Messages: ". $check-&gt;Nmsgs   ."&lt;br&gt;\n" ;
    print "Recent: "  . $check-&gt;Recent  ."&lt;br&gt;\n" ;
    print "Unread: "  . $check-&gt;Unread  ."&lt;br&gt;\n" ;
    print "Deleted: " . $check-&gt;Deleted ."&lt;br&gt;\n" ;
    print "Size: "    . $check-&gt;Size    ."&lt;br&gt;\n" ;
} else {
    print "imap_check() failed: ".imap_last_error(). "&lt;br&gt;\n";
}
 
imap_close($mbox);


?&gt;
So it is recommended to put it like this '{unread}' in that mysql query

Posted: Thu Jan 08, 2004 7:55 am
by malcolmboston
lol no offence fastfinger but youve moved too fast for me

im still a bit of a noob, can you explain what it does and what its for and where exactly do i get them, variables in the first place from?

does anyone know why i cant show the data the way i normally do it?

Code: Select all

<?php
print $data['username'];<br>
print $data['gender'];
?>

or will it now work

Posted: Thu Jan 08, 2004 7:58 am
by fastfingertips
Isn't <br> a html tag?

This should be ok:
print '$data['username']<br>';
print $data['gender'];

Posted: Thu Jan 08, 2004 8:00 am
by malcolmboston
i was just doing it fast

Posted: Thu Jan 08, 2004 8:01 am
by fastfingertips
Is now ok?

Posted: Thu Jan 08, 2004 8:03 am
by JayBird
change this

Code: Select all

//ways of showing the data 
//none work 
php print $query 
<br> 
php print $result 
<br> 
php print $data 
<br>
to

Code: Select all

//ways of showing the data 
//none work 
print $query;
echo "<br>"; 
print $result;
echo "<br>";
print $data;
echo "<br>";
Mark

P.S. Fastfingertips, i think you should be more concice when posting your messages. I know your a noob and are all excited, but i think your posts have confused this thread quite a lot. Just a pointer, not having a go or anything :wink:

Posted: Thu Jan 08, 2004 8:04 am
by malcolmboston
i dont know yet, sorry

i dont understand what this is for

Code: Select all

<?php 
$mbox = imap_open("{your.imap.host}INBOX","username", "password") 
      or die("can't connect: ".imap_last_error()); 

$check = imap_mailboxmsginfo($mbox); 

if($check) { 
    print "Date: "    . $check->Date    ."<br>\n" ; 
    print "Driver: "  . $check->Driver  ."<br>\n" ; 
    print "Mailbox: " . $check->Mailbox ."<br>\n" ; 
    print "Messages: ". $check->Nmsgs   ."<br>\n" ; 
    print "Recent: "  . $check->Recent  ."<br>\n" ; 
    print "Unread: "  . $check->Unread  ."<br>\n" ; 
    print "Deleted: " . $check->Deleted ."<br>\n" ; 
    print "Size: "    . $check->Size    ."<br>\n" ; 
} else { 
    print "imap_check() failed: ".imap_last_error(). "<br>\n"; 
} 

imap_close($mbox); 
?>

Posted: Thu Jan 08, 2004 8:05 am
by malcolmboston
lol bech,

either way works (in zend anyway) and besides i know how to do that, i was just typing that bit up fast. that isnt a problem in my script.

edit.. probably copied and pasted code anyway, doesnt seem to fit in at all with my project

Posted: Thu Jan 08, 2004 8:06 am
by JayBird
so what is the problem now? Did you change the query?

Mark