LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-30-2007, 04:40 PM   #1
waelaltaqi
Member
 
Registered: Sep 2005
Location: USA, TN
Distribution: CentOS & Ubuntu for Desktop
Posts: 454

Rep: Reputation: 31
No PHP output for mailscanner msql


Hello all,
first off, i'm just starting to learn PHP so excuse my question if it didn't meet other's standards.

I'm trying to write a PHP script that will query Mailscanner mysql db for all mail received for a certain domain within the month period:
Code:
<?php
// Building mysql connection
$con = mysql_connect("localhost","root","mypass");
if (!$con)
  {
  die ('Could not connect:' . mysql_error());
  }
// Selecting Database
mysql_select_db("mailscanner", $con);

$allmail = mysql_query("SELECT COUNT(*) FROM maillog WHERE to_domain="mydomain.com" AND MONTH(date) = MONTH(CURRENT_DATE)");

//Printing output
echo $allmail;

mysql_close($con);
?>
i'm not quit sure why the script is not giving any ouput. I tried to output couple of simpler mysql queries and they worked fine. I also tested the sql query above within the mysql shell and it worked fine.After i pass this point i'm going to try writting similar scripts for spam and virus mail. I'm kind of stuck here and i need your guys help.

I will appreciate any help...

Last edited by waelaltaqi; 09-30-2007 at 04:43 PM.
 
Old 09-30-2007, 08:07 PM   #2
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
The mysql_query function returns a "resource" to the result set and not the result itself. So you can't actually print it directly. Here is an example from the PHP manual on how you can get the actual results of your query.
PHP Code:
<?php
// Connecting, selecting database
$link mysql_connect('mysql_host''mysql_user''mysql_password')
    or die(
'Could not connect: ' mysql_error());
echo 
'Connected successfully';
mysql_select_db('my_database') or die('Could not select database');

// Performing SQL query
$query 'SELECT * FROM my_table';
$result mysql_query($query) or die('Query failed: ' mysql_error());

// Printing results in HTML
echo "<table>\n";
while (
$line mysql_fetch_array($resultMYSQL_ASSOC)) {
    echo 
"\t<tr>\n";
    foreach (
$line as $col_value) {
        echo 
"\t\t<td>$col_value</td>\n";
    }
    echo 
"\t</tr>\n";
}
echo 
"</table>\n";

// Free resultset
mysql_free_result($result);

// Closing connection
mysql_close($link);
?>
 
Old 10-01-2007, 10:33 AM   #3
waelaltaqi
Member
 
Registered: Sep 2005
Location: USA, TN
Distribution: CentOS & Ubuntu for Desktop
Posts: 454

Original Poster
Rep: Reputation: 31
it worked for a simpler mysql script but not the one i'm intending to use. there is something wrong with the sql query or the way i wrote in the php script. the script right now is:

Code:
<?php
$con = mysql_connect("localhost","root","iwfcti4743");
if (!$con)
  {
    die('Could not connect:' . mysql_error());
  }

mysql_select_db("mailscanner", $con);

$result = mysql_query("select COUNT(*) as 'AllMSG' from maillog where to_domain="ctiemail.com" AND MONTH(date) = MONTH(CURRENT_D)");

while($row = mysql_fetch_array($result, MYSQL_ACCOS))
    {
    echo $row['ALLMSG'];
   }

mysql_close($con);
?>
when i look at /var/www/httpd/error_log, it comes back with this:

Code:
[client 127.0.0.1] PHP Parse error:  parse error, unexpected T_STRING in /var/www/html/test.php on line 10
i tried what you mentioned with much simpler queries and it worked. my problem now is obviously on the $result line...
i would appreciate further help and thanks in advance

Last edited by waelaltaqi; 10-01-2007 at 10:35 AM.
 
Old 10-01-2007, 05:26 PM   #4
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
You need to escape the double quotes in your string. That is:
PHP Code:
$result mysql_query("select COUNT(*) as 'AllMSG' from maillog where to_domain=\"ctiemail.com\" AND MONTH(date) = MONTH(CURRENT_D)"); 
Otherwise when php comes to the double quote before ctiemail.com it treats that as a close quote to the whole string, and then it gets confused when it sees the label ctiemail.com and doesn't know how to proceed.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
CGI Output in PHP ACDII Programming 7 12-05-2006 12:39 PM
Question about output for php Hockeyfan Programming 1 03-14-2006 09:30 AM
No form output in PHP jabfinger Programming 2 07-15-2005 06:48 PM
Apache PhP MSQL - if they come with fedora core 1 where are they Virtualhate Linux - Newbie 1 05-16-2004 08:33 PM
Php output robbfen Linux - Newbie 2 06-20-2003 12:03 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration