By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,650 Members | 1,785 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,650 IT Pros & Developers. It's quick & easy.

problem with this code..??

P: n/a
I am having a bit of a problem with some code....can someone give me
some suggestions?

Parse error: syntax error, unexpected '{' in C:\xampp\htdocs\production
\date2.php on line 28

line 28 is this line:
while($row = mysql_fetch_array(mysql_query($sql)) {

It is the first while..
HERE IS THE CODE:
Generating and emailing report for:
<?php
$today = date("M j, Y,");
echo $today;

$host="localhost";
$user="root";
$pass="";
$db="productiondb";
$con = mysql_connect($host, $user, $pass);

if (!$con)
{
die('Unable to connect: ' . mysql_error());
}
mysql_select_db($db, $con) or die('Unable to connect: ' .
mysql_error());

// Get results from first table
$sql = "SELECT * FROM editorial WHERE editorialdate LIKE '$today%'
";
$sql2 = "SELECT * FROM prepress WHERE prepressdate LIKE '$today%' ";

// Begin our email body
$messageBody = "Production Report follows for all departments: /r/
n";
//if (mysql_num_rows($result)) { // if there are results
// Add results from first query to email
while($row = mysql_fetch_array(mysql_query($sql)){
$messageBody .= "Editorial Date: " . $row['editorialdate'];
$messageBody .= "/r/n";
$messageBody .= "Editorial Name: " . $row['editorialname'];
$messageBody .= "/r/n";
$messageBody .= "Editorial Comments: " . $row['editorialcomments'];
$messageBody .= "/r/n";
}

// Add results from second query to email
while($row = mysql_fetch_array(mysql_query($sql2)) {
$messageBody .= "PrePress Date: " . $row['prepressdate'];
$messageBody .= "/r/n";
$messageBody .= "Prepress Name: " . $row['prepressname'];
$messageBody .= "/r/n";
$messageBody .= "Prepress Comments: " . $row['prepresscomments'];
$messageBody .= "/r/n";
}

// Send email
ini_set("SMTP", "texchange.company.com");
ini_set("smtp_port", "25");
mail("pa**@company.com","Production Report",$messageBody);

mysql_close($con); //closes the connection to the DB
?>

thanks for any help
Jan 2 '08 #1
Share this Question
Share on Google+
10 Replies


P: n/a
On Jan 2, 9:16 am, paul...@excite.com wrote:
I am having a bit of a problem with some code....can someone give me
some suggestions?

Parse error: syntax error, unexpected '{' in C:\xampp\htdocs\production
\date2.php on line 28

line 28 is this line:
while($row = mysql_fetch_array(mysql_query($sql)) {

It is the first while..
HERE IS THE CODE:
Generating and emailing report for:
<?php
$today = date("M j, Y,");
echo $today;

$host="localhost";
$user="root";
$pass="";
$db="productiondb";
$con = mysql_connect($host, $user, $pass);

if (!$con)
{
die('Unable to connect: ' . mysql_error());
}
mysql_select_db($db, $con) or die('Unable to connect: ' .
mysql_error());

// Get results from first table
$sql = "SELECT * FROM editorial WHERE editorialdate LIKE '$today%'
";
$sql2 = "SELECT * FROM prepress WHERE prepressdate LIKE '$today%' ";

// Begin our email body
$messageBody = "Production Report follows for all departments: /r/
n";

//if (mysql_num_rows($result)) { // if there are results
// Add results from first query to email
while($row = mysql_fetch_array(mysql_query($sql)){
$messageBody .= "Editorial Date: " . $row['editorialdate'];
$messageBody .= "/r/n";
$messageBody .= "Editorial Name: " . $row['editorialname'];
$messageBody .= "/r/n";
$messageBody .= "Editorial Comments: " . $row['editorialcomments'];
$messageBody .= "/r/n";
}

// Add results from second query to email
while($row = mysql_fetch_array(mysql_query($sql2)) {
$messageBody .= "PrePress Date: " . $row['prepressdate'];
$messageBody .= "/r/n";
$messageBody .= "Prepress Name: " . $row['prepressname'];
$messageBody .= "/r/n";
$messageBody .= "Prepress Comments: " . $row['prepresscomments'];
$messageBody .= "/r/n";
}

// Send email
ini_set("SMTP", "texchange.company.com");
ini_set("smtp_port", "25");
mail("p...@company.com","Production Report",$messageBody);

mysql_close($con); //closes the connection to the DB
?>

thanks for any help
I changed my code a bit because I did not have a couple ) and also
added if (mysql_num_rows($result)) { // if there are results

Now I get this error on the last line of my code the last line is my: ?
>
the error is:
Parse error: syntax error, unexpected $end in C:\xampp\htdocs
\production\date2.php on line 54
Jan 2 '08 #2

P: n/a
On Jan 2, 9:26 am, paul...@excite.com wrote:
On Jan 2, 9:16 am, paul...@excite.com wrote:
I am having a bit of a problem with some code....can someone give me
some suggestions?
Parse error: syntax error, unexpected '{' in C:\xampp\htdocs\production
\date2.php on line 28
line 28 is this line:
while($row = mysql_fetch_array(mysql_query($sql)) {
It is the first while..
HERE IS THE CODE:
Generating and emailing report for:
<?php
$today = date("M j, Y,");
echo $today;
$host="localhost";
$user="root";
$pass="";
$db="productiondb";
$con = mysql_connect($host, $user, $pass);
if (!$con)
{
die('Unable to connect: ' . mysql_error());
}
mysql_select_db($db, $con) or die('Unable to connect: ' .
mysql_error());
// Get results from first table
$sql = "SELECT * FROM editorial WHERE editorialdate LIKE '$today%'
";
$sql2 = "SELECT * FROM prepress WHERE prepressdate LIKE '$today%' ";
// Begin our email body
$messageBody = "Production Report follows for all departments: /r/
n";
//if (mysql_num_rows($result)) { // if there are results
// Add results from first query to email
while($row = mysql_fetch_array(mysql_query($sql)){
$messageBody .= "Editorial Date: " . $row['editorialdate'];
$messageBody .= "/r/n";
$messageBody .= "Editorial Name: " . $row['editorialname'];
$messageBody .= "/r/n";
$messageBody .= "Editorial Comments: " . $row['editorialcomments'];
$messageBody .= "/r/n";
}
// Add results from second query to email
while($row = mysql_fetch_array(mysql_query($sql2)) {
$messageBody .= "PrePress Date: " . $row['prepressdate'];
$messageBody .= "/r/n";
$messageBody .= "Prepress Name: " . $row['prepressname'];
$messageBody .= "/r/n";
$messageBody .= "Prepress Comments: " . $row['prepresscomments'];
$messageBody .= "/r/n";
}
// Send email
ini_set("SMTP", "texchange.company.com");
ini_set("smtp_port", "25");
mail("p...@company.com","Production Report",$messageBody);
mysql_close($con); //closes the connection to the DB
?>
thanks for any help

I changed my code a bit because I did not have a couple ) and also
added if (mysql_num_rows($result)) { // if there are results

Now I get this error on the last line of my code the last line is my: ?

the error is:
Parse error: syntax error, unexpected $end in C:\xampp\htdocs
\production\date2.php on line 54
Sorry, forgot to include the updated code:
Generating and emailing report for:
<?php
$today = date("M j, Y,");
echo $today;

$host="localhost";
$user="root";
$pass="";
$db="productiondb";
$con = mysql_connect($host, $user, $pass);

if (!$con)
{
die('Unable to connect: ' . mysql_error());
}
mysql_select_db($db, $con) or die('Unable to connect: ' .
mysql_error());

// Get results from first table
$sql = "SELECT * FROM editorial WHERE editorialdate LIKE '$today%'
";
$sql2 = "SELECT * FROM prepress WHERE prepressdate LIKE '$today%' ";

// Begin our email body
$messageBody = "Production Report follows for all departments: /r/
n";
if (mysql_num_rows($result)) { // if there are results
// Add results from first query to email
while($row = mysql_fetch_array(mysql_query($sql))){
$messageBody .= "Editorial Date: " . $row['editorialdate'];
$messageBody .= "/r/n";
$messageBody .= "Editorial Name: " . $row['editorialname'];
$messageBody .= "/r/n";
$messageBody .= "Editorial Comments: " . $row['editorialcomments'];
$messageBody .= "/r/n";
}

// Add results from second query to email
while($row = mysql_fetch_array(mysql_query($sql2))) {
$messageBody .= "PrePress Date: " . $row['prepressdate'];
$messageBody .= "/r/n";
$messageBody .= "Prepress Name: " . $row['prepressname'];
$messageBody .= "/r/n";
$messageBody .= "Prepress Comments: " . $row['prepresscomments'];
$messageBody .= "/r/n";
}

mysql_close($con); //closes the connection to the DB

// Send email
ini_set("SMTP", "texchange.company.com");
ini_set("smtp_port", "25");
mail("pa**@company.com","Production Report",$messageBody);
?>
Jan 2 '08 #3

P: n/a
In article
<52**********************************@e50g2000hsh. googlegroups.com>,
pa*****@excite.com wrote:
On Jan 2, 9:26 am, paul...@excite.com wrote:
On Jan 2, 9:16 am, paul...@excite.com wrote:
I am having a bit of a problem with some code....can someone give me
some suggestions?
Parse error: syntax error, unexpected '{' in C:\xampp\htdocs\production
\date2.php on line 28
line 28 is this line:
while($row = mysql_fetch_array(mysql_query($sql)) {
It is the first while..
HERE IS THE CODE:
Generating and emailing report for:
<?php
$today = date("M j, Y,");
echo $today;
$host="localhost";
$user="root";
$pass="";
$db="productiondb";
$con = mysql_connect($host, $user, $pass);
if (!$con)
{
die('Unable to connect: ' . mysql_error());
}
mysql_select_db($db, $con) or die('Unable to connect: ' .
mysql_error());
// Get results from first table
$sql = "SELECT * FROM editorial WHERE editorialdate LIKE '$today%'
";
$sql2 = "SELECT * FROM prepress WHERE prepressdate LIKE '$today%' ";
// Begin our email body
$messageBody = "Production Report follows for all departments: /r/
n";
//if (mysql_num_rows($result)) { // if there are results
// Add results from first query to email
while($row = mysql_fetch_array(mysql_query($sql)){
$messageBody .= "Editorial Date: " . $row['editorialdate'];
$messageBody .= "/r/n";
$messageBody .= "Editorial Name: " . $row['editorialname'];
$messageBody .= "/r/n";
$messageBody .= "Editorial Comments: " .
$row['editorialcomments'];
$messageBody .= "/r/n";
}
// Add results from second query to email
while($row = mysql_fetch_array(mysql_query($sql2)) {
$messageBody .= "PrePress Date: " . $row['prepressdate'];
$messageBody .= "/r/n";
$messageBody .= "Prepress Name: " . $row['prepressname'];
$messageBody .= "/r/n";
$messageBody .= "Prepress Comments: " . $row['prepresscomments'];
$messageBody .= "/r/n";
}
// Send email
ini_set("SMTP", "texchange.company.com");
ini_set("smtp_port", "25");
mail("p...@company.com","Production Report",$messageBody);
mysql_close($con); //closes the connection to the DB
?>
thanks for any help
I changed my code a bit because I did not have a couple ) and also
added if (mysql_num_rows($result)) { // if there are results

Now I get this error on the last line of my code the last line is my: ?

the error is:
Parse error: syntax error, unexpected $end in C:\xampp\htdocs
\production\date2.php on line 54

Sorry, forgot to include the updated code:
Generating and emailing report for:
<?php
$today = date("M j, Y,");
echo $today;

$host="localhost";
$user="root";
$pass="";
$db="productiondb";
$con = mysql_connect($host, $user, $pass);

if (!$con)
{
die('Unable to connect: ' . mysql_error());
}
mysql_select_db($db, $con) or die('Unable to connect: ' .
mysql_error());

// Get results from first table
$sql = "SELECT * FROM editorial WHERE editorialdate LIKE '$today%'
";
$sql2 = "SELECT * FROM prepress WHERE prepressdate LIKE '$today%' ";

// Begin our email body
$messageBody = "Production Report follows for all departments: /r/
n";
if (mysql_num_rows($result)) { // if there are results
This 'if' has no closing }

I always give the { and the } the same indentation so it's easy to see
that one is missing:

if (mysql_num_rows($result))
{
// if there are results
// Add results from first query to email
while ($row = mysql_fetch_array(mysql_query($sql)))
{
$messageBody .= "Editorial Date: " . $row['editorialdate'];
$messageBody .= "/r/n";
$messageBody .= "Editorial Name: " . $row['editorialname'];
$messageBody .= "/r/n";
$messageBody .= "Editorial Comments: " .
$row['editorialcomments'];
$messageBody .= "/r/n";
}

// Add results from second query to email
while ($row = mysql_fetch_array(mysql_query($sql2)))
{
$messageBody .= "PrePress Date: " . $row['prepressdate'];
$messageBody .= "/r/n";
$messageBody .= "Prepress Name: " . $row['prepressname'];
$messageBody .= "/r/n";
$messageBody .= "Prepress Comments: " .
$row['prepresscomments'];
$messageBody .= "/r/n";
}

<--------- where's the } ????

mysql_close($con); //closes the connection to the DB

// Send email
ini_set("SMTP", "texchange.company.com");
ini_set("smtp_port", "25");
mail("pa**@company.com","Production Report",$messageBody);

?>
Jan 2 '08 #4

P: n/a
On Jan 2, 9:53 am, Tim Streater <tim.strea...@dante.org.ukwrote:
In article
<52120bfd-b2a0-4b8f-a3e6-f96cf2793...@e50g2000hsh.googlegroups.com>,

paul...@excite.com wrote:
On Jan 2, 9:26 am, paul...@excite.com wrote:
On Jan 2, 9:16 am, paul...@excite.com wrote:
I am having a bit of a problem with some code....can someone give me
some suggestions?
Parse error: syntax error, unexpected '{' in C:\xampp\htdocs\production
\date2.php on line 28
line 28 is this line:
while($row = mysql_fetch_array(mysql_query($sql)) {
It is the first while..
HERE IS THE CODE:
Generating and emailing report for:
<?php
$today = date("M j, Y,");
echo $today;
$host="localhost";
$user="root";
$pass="";
$db="productiondb";
$con = mysql_connect($host, $user, $pass);
if (!$con)
{
die('Unable to connect: ' . mysql_error());
}
mysql_select_db($db, $con) or die('Unable to connect: ' .
mysql_error());
// Get results from first table
$sql = "SELECT * FROM editorial WHERE editorialdate LIKE '$today%'
";
$sql2 = "SELECT * FROM prepress WHERE prepressdate LIKE '$today%' ";
// Begin our email body
$messageBody = "Production Report follows for all departments: /r/
n";
//if (mysql_num_rows($result)) { // if there are results
// Add results from first query to email
while($row = mysql_fetch_array(mysql_query($sql)){
$messageBody .= "Editorial Date: " . $row['editorialdate'];
$messageBody .= "/r/n";
$messageBody .= "Editorial Name: " . $row['editorialname'];
$messageBody .= "/r/n";
$messageBody .= "Editorial Comments: " .
$row['editorialcomments'];
$messageBody .= "/r/n";
}
// Add results from second query to email
while($row = mysql_fetch_array(mysql_query($sql2)) {
$messageBody .= "PrePress Date: " . $row['prepressdate'];
$messageBody .= "/r/n";
$messageBody .= "Prepress Name: " . $row['prepressname'];
$messageBody .= "/r/n";
$messageBody .= "Prepress Comments: " . $row['prepresscomments'];
$messageBody .= "/r/n";
}
// Send email
ini_set("SMTP", "texchange.company.com");
ini_set("smtp_port", "25");
mail("p...@company.com","Production Report",$messageBody);
mysql_close($con); //closes the connection to the DB
?>
thanks for any help
I changed my code a bit because I did not have a couple ) and also
added if (mysql_num_rows($result)) { // if there are results
Now I get this error on the last line of my code the last line is my: ?
the error is:
Parse error: syntax error, unexpected $end in C:\xampp\htdocs
\production\date2.php on line 54
Sorry, forgot to include the updated code:
Generating and emailing report for:
<?php
$today = date("M j, Y,");
echo $today;
$host="localhost";
$user="root";
$pass="";
$db="productiondb";
$con = mysql_connect($host, $user, $pass);
if (!$con)
{
die('Unable to connect: ' . mysql_error());
}
mysql_select_db($db, $con) or die('Unable to connect: ' .
mysql_error());
// Get results from first table
$sql = "SELECT * FROM editorial WHERE editorialdate LIKE '$today%'
";
$sql2 = "SELECT * FROM prepress WHERE prepressdate LIKE '$today%' ";
// Begin our email body
$messageBody = "Production Report follows for all departments: /r/
n";
if (mysql_num_rows($result)) { // if there are results

This 'if' has no closing }

I always give the { and the } the same indentation so it's easy to see
that one is missing:

if (mysql_num_rows($result))
{
// if there are results
// Add results from first query to email
while ($row = mysql_fetch_array(mysql_query($sql)))
{
$messageBody .= "Editorial Date: " . $row['editorialdate'];
$messageBody .= "/r/n";
$messageBody .= "Editorial Name: " . $row['editorialname'];
$messageBody .= "/r/n";
$messageBody .= "Editorial Comments: " .
$row['editorialcomments'];
$messageBody .= "/r/n";
}

// Add results from second query to email
while ($row = mysql_fetch_array(mysql_query($sql2)))
{
$messageBody .= "PrePress Date: " . $row['prepressdate'];
$messageBody .= "/r/n";
$messageBody .= "Prepress Name: " . $row['prepressname'];
$messageBody .= "/r/n";
$messageBody .= "Prepress Comments: " .
$row['prepresscomments'];
$messageBody .= "/r/n";
}

<--------- where's the } ????

mysql_close($con); //closes the connection to the DB

// Send email
ini_set("SMTP", "texchange.company.com");
ini_set("smtp_port", "25");
mail("p...@company.com","Production Report",$messageBody);

?>
OK I think I am getting closer, thanks for the help.
I am getting this error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL
result resource in C:\xampp\htdocs\production\date2.php on line 26

this is my code as of now:
Generating and emailing report for:
<?php
$today = date("M j, Y,");
echo $today;

$host="localhost";
$user="root";
$pass="";
$db="productiondb";
$con = mysql_connect($host, $user, $pass);

if (!$con)
{
die('Unable to connect: ' . mysql_error());
}
mysql_select_db($db, $con) or die('Unable to connect: ' .
mysql_error());

// Get results from first table
$sql = "SELECT * FROM editorial WHERE editorialdate LIKE '$today%'
";
$sql2 = "SELECT * FROM prepress WHERE prepressdate LIKE '$today%' ";

// Begin our email body
$messageBody = "Production Report follows for all departments: /r/
n";
if (mysql_num_rows($result)) { // if there are results
// Add results from first query to email
while($row = mysql_fetch_array(mysql_query($sql))){
$messageBody .= "Editorial Date: " . $row['editorialdate'];
$messageBody .= "/r/n";
$messageBody .= "Editorial Name: " . $row['editorialname'];
$messageBody .= "/r/n";
$messageBody .= "Editorial Comments: " . $row['editorialcomments'];
$messageBody .= "/r/n";
}

// Add results from second query to email
while($row = mysql_fetch_array(mysql_query($sql2))) {
$messageBody .= "PrePress Date: " . $row['prepressdate'];
$messageBody .= "/r/n";
$messageBody .= "Prepress Name: " . $row['prepressname'];
$messageBody .= "/r/n";
$messageBody .= "Prepress Comments: " . $row['prepresscomments'];
$messageBody .= "/r/n";
}
}

mysql_close($con); //closes the connection to the DB

// Send email
ini_set("SMTP", "texchange.company.com");
ini_set("smtp_port", "25");
$headers = "From: Pr******************@company.com";
mail("pa**@company.com","Production Report",$messageBody,$headers);
?>

And I do get an email, all that is in the email though is:
Production Report follows for all departments: /r/n
Jan 2 '08 #5

P: n/a
pa*****@excite.com wrote:
OK I think I am getting closer, thanks for the help.
I am getting this error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL
result resource in C:\xampp\htdocs\production\date2.php on line 26
Thats because you never made a query at all.

this is my code as of now:
Generating and emailing report for:
<?php
$today = date("M j, Y,");
echo $today;

$host="localhost";
$user="root";
$pass="";
$db="productiondb";
$con = mysql_connect($host, $user, $pass);

if (!$con)
{
die('Unable to connect: ' . mysql_error());
}
mysql_select_db($db, $con) or die('Unable to connect: ' .
mysql_error());

// Get results from first table
$sql = "SELECT * FROM editorial WHERE editorialdate LIKE '$today%'
";
$sql2 = "SELECT * FROM prepress WHERE prepressdate LIKE '$today%' ";

// Begin our email body
$messageBody = "Production Report follows for all departments: /r/
n";
//You need a
$result=mysql_query($sql); // in here
>
if (mysql_num_rows($result)) { // if there are results
// Add results from first query to email
while($row = mysql_fetch_array(mysql_query($sql))){
$messageBody .= "Editorial Date: " . $row['editorialdate'];
$messageBody .= "/r/n";
$messageBody .= "Editorial Name: " . $row['editorialname'];
$messageBody .= "/r/n";
$messageBody .= "Editorial Comments: " . $row['editorialcomments'];
$messageBody .= "/r/n";
}

// Add results from second query to email
while($row = mysql_fetch_array(mysql_query($sql2))) {
$messageBody .= "PrePress Date: " . $row['prepressdate'];
$messageBody .= "/r/n";
$messageBody .= "Prepress Name: " . $row['prepressname'];
$messageBody .= "/r/n";
$messageBody .= "Prepress Comments: " . $row['prepresscomments'];
$messageBody .= "/r/n";
}
}

mysql_close($con); //closes the connection to the DB

// Send email
ini_set("SMTP", "texchange.company.com");
ini_set("smtp_port", "25");
$headers = "From: Pr******************@company.com";
mail("pa**@company.com","Production Report",$messageBody,$headers);
?>

And I do get an email, all that is in the email though is:
Production Report follows for all departments: /r/n
Jan 2 '08 #6

P: n/a
On Jan 2, 12:18 pm, The Natural Philosopher <a...@b.cwrote:
paul...@excite.com wrote:
OK I think I am getting closer, thanks for the help.
I am getting this error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL
result resource in C:\xampp\htdocs\production\date2.php on line 26

Thats because you never made a query at all.
this is my code as of now:
Generating and emailing report for:
<?php
$today = date("M j, Y,");
echo $today;
$host="localhost";
$user="root";
$pass="";
$db="productiondb";
$con = mysql_connect($host, $user, $pass);
if (!$con)
{
die('Unable to connect: ' . mysql_error());
}
mysql_select_db($db, $con) or die('Unable to connect: ' .
mysql_error());
// Get results from first table
$sql = "SELECT * FROM editorial WHERE editorialdate LIKE '$today%'
";
$sql2 = "SELECT * FROM prepress WHERE prepressdate LIKE '$today%' ";
// Begin our email body
$messageBody = "Production Report follows for all departments: /r/
n";

//You need a
$result=mysql_query($sql); // in here
if (mysql_num_rows($result)) { // if there are results
// Add results from first query to email
while($row = mysql_fetch_array(mysql_query($sql))){
$messageBody .= "Editorial Date: " . $row['editorialdate'];
$messageBody .= "/r/n";
$messageBody .= "Editorial Name: " . $row['editorialname'];
$messageBody .= "/r/n";
$messageBody .= "Editorial Comments: " . $row['editorialcomments'];
$messageBody .= "/r/n";
}
// Add results from second query to email
while($row = mysql_fetch_array(mysql_query($sql2))) {
$messageBody .= "PrePress Date: " . $row['prepressdate'];
$messageBody .= "/r/n";
$messageBody .= "Prepress Name: " . $row['prepressname'];
$messageBody .= "/r/n";
$messageBody .= "Prepress Comments: " . $row['prepresscomments'];
$messageBody .= "/r/n";
}
}
mysql_close($con); //closes the connection to the DB
// Send email
ini_set("SMTP", "texchange.company.com");
ini_set("smtp_port", "25");
$headers = "From: Prod.Report_PREPR...@company.com";
mail("p...@company.com","Production Report",$messageBody,$headers);
?>
And I do get an email, all that is in the email though is:
Production Report follows for all departments: /r/n
so will I need one of these IF statements before each one of my:
while($row = mysql_fetch_array(mysql_query($sql))){

and then do I also need multiple:
$result=mysql_query($sql);
only use $sql2 etc?
Jan 2 '08 #7

P: n/a
In article
<fc**********************************@j20g2000hsi. googlegroups.com>,
pa*****@excite.com wrote:

[snip]
>
OK I think I am getting closer, thanks for the help.
I am getting this error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL
result resource in C:\xampp\htdocs\production\date2.php on line 26

this is my code as of now:
Generating and emailing report for:
<?php
$today = date("M j, Y,");
echo $today;

$host="localhost";
$user="root";
$pass="";
$db="productiondb";
$con = mysql_connect($host, $user, $pass);

if (!$con)
{
die('Unable to connect: ' . mysql_error());
}
mysql_select_db($db, $con) or die('Unable to connect: ' .
mysql_error());

// Get results from first table
$sql = "SELECT * FROM editorial WHERE editorialdate LIKE '$today%'
";
$sql2 = "SELECT * FROM prepress WHERE prepressdate LIKE '$today%' ";

// Begin our email body
$messageBody = "Production Report follows for all departments: /r/
n";
<----- try doing a query *before* asking how many rows it generated.

$result = mysql_query ($sql);
$numrows = mysql_num_rows ($result);
if ($numrows>0)
{
while ($row = mysql_fetch_array ($result))
{
// add first results
...
}
}
mysql_free_result ($result);

// now do the same for the other query

if (mysql_num_rows($result)) { // if there are results
// Add results from first query to email
while($row = mysql_fetch_array(mysql_query($sql))){
$messageBody .= "Editorial Date: " . $row['editorialdate'];

How do you expect this to work? Every time round the while loop, you do
the mysql_query again and fetch the first row of the results. You
shouldn't nest these calls.

I would also suggest a more tidy layout which will help you debug more
easily.
Jan 2 '08 #8

P: n/a
In article
<19**********************************@x69g2000hsx. googlegroups.com>,
pa*****@excite.com wrote:

[snip]
if (mysql_num_rows($result)) { // if there are results
// Add results from first query to email
while($row = mysql_fetch_array(mysql_query($sql))){
$messageBody .= "Editorial Date: " . $row['editorialdate'];
$messageBody .= "/r/n";
$messageBody .= "Editorial Name: " . $row['editorialname'];
$messageBody .= "/r/n";
$messageBody .= "Editorial Comments: " . $row['editorialcomments'];
$messageBody .= "/r/n";
}
// Add results from second query to email
while($row = mysql_fetch_array(mysql_query($sql2))) {
$messageBody .= "PrePress Date: " . $row['prepressdate'];
$messageBody .= "/r/n";
$messageBody .= "Prepress Name: " . $row['prepressname'];
$messageBody .= "/r/n";
$messageBody .= "Prepress Comments: " . $row['prepresscomments'];
$messageBody .= "/r/n";
}
}
mysql_close($con); //closes the connection to the DB
// Send email
ini_set("SMTP", "texchange.company.com");
ini_set("smtp_port", "25");
$headers = "From: Prod.Report_PREPR...@company.com";
mail("p...@company.com","Production Report",$messageBody,$headers);
?>
And I do get an email, all that is in the email though is:
Production Report follows for all departments: /r/n

so will I need one of these IF statements before each one of my:
while($row = mysql_fetch_array(mysql_query($sql))){

and then do I also need multiple:
$result=mysql_query($sql);
only use $sql2 etc?
If you don't do a query, you won't have any results. If you have two
query strings, you obviously gotta do two queries.

If you got two queries, you got to check each one to see if it returned
any results. Why do you think the first IF which covers the first query,
should also cover the second?
Jan 2 '08 #9

P: n/a
On Jan 2, 12:33 pm, Tim Streater <tim.strea...@dante.org.ukwrote:
In article
<fc01e709-a824-4662-a4f3-1d5fad0d5...@j20g2000hsi.googlegroups.com>,

paul...@excite.com wrote:

[snip]


OK I think I am getting closer, thanks for the help.
I am getting this error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL
result resource in C:\xampp\htdocs\production\date2.php on line 26
this is my code as of now:
Generating and emailing report for:
<?php
$today = date("M j, Y,");
echo $today;
$host="localhost";
$user="root";
$pass="";
$db="productiondb";
$con = mysql_connect($host, $user, $pass);
if (!$con)
{
die('Unable to connect: ' . mysql_error());
}
mysql_select_db($db, $con) or die('Unable to connect: ' .
mysql_error());
// Get results from first table
$sql = "SELECT * FROM editorial WHERE editorialdate LIKE '$today%'
";
$sql2 = "SELECT * FROM prepress WHERE prepressdate LIKE '$today%' ";
// Begin our email body
$messageBody = "Production Report follows for all departments: /r/
n";

<----- try doing a query *before* asking how many rows it generated.

$result = mysql_query ($sql);
$numrows = mysql_num_rows ($result);
if ($numrows>0)
{
while ($row = mysql_fetch_array ($result))
{
// add first results
...
}
}
mysql_free_result ($result);

// now do the same for the other query
if (mysql_num_rows($result)) { // if there are results
// Add results from first query to email
while($row = mysql_fetch_array(mysql_query($sql))){
$messageBody .= "Editorial Date: " . $row['editorialdate'];

How do you expect this to work? Every time round the while loop, you do
the mysql_query again and fetch the first row of the results. You
shouldn't nest these calls.

I would also suggest a more tidy layout which will help you debug more
easily.
OK I am seeing this now, after adding this:
$result=mysql_query($sql);
It looks like my page is just in a loop, because it just continues to
try to load.

Looking at this code I think it will loop through and do a search on
$SQL until it does not find any other records matching, than it will
go down and do the same thing for $sql2 while there is something
there, all the time putting it into $messagebody

Am I close? What am I doing wrong?
most updated code as of now...now it looks like the page is just
looping......
Generating and emailing report for:
<?php
$today = date("M j, Y,");
echo $today;

$host="localhost";
$user="root";
$pass="";
$db="productiondb";
$con = mysql_connect($host, $user, $pass);

if (!$con)
{
die('Unable to connect: ' . mysql_error());
}
mysql_select_db($db, $con) or die('Unable to connect: ' .
mysql_error());

// Get results from first table
$sql = "SELECT * FROM editorial WHERE editorialdate LIKE '$today%'
";
$sql2 = "SELECT * FROM prepress WHERE prepressdate LIKE '$today%' ";

// Begin our email body
$messageBody = "Production Report follows for all departments: /r/
n";
$result=mysql_query($sql);

if (mysql_num_rows($result)) { // if there are results

// Add results from first query to email

while($row = mysql_fetch_array(mysql_query($sql))){
$messageBody .= "Editorial Date: " . $row['editorialdate'];
$messageBody .= "/r/n";
$messageBody .= "Editorial Name: " . $row['editorialname'];
$messageBody .= "/r/n";
$messageBody .= "Editorial Comments: " . $row['editorialcomments'];
$messageBody .= "/r/n";
}

// Add results from second query to email
while($row = mysql_fetch_array(mysql_query($sql2))) {
$messageBody .= "PrePress Date: " . $row['prepressdate'];
$messageBody .= "/r/n";
$messageBody .= "Prepress Name: " . $row['prepressname'];
$messageBody .= "/r/n";
$messageBody .= "Prepress Comments: " . $row['prepresscomments'];
$messageBody .= "/r/n";
}
}
mysql_close($con); //closes the connection to the DB

// Send email
ini_set("SMTP", "texchange.company.com");
ini_set("smtp_port", "25");
$headers = "From: Pr******************@company.com";
mail("pa**@company.com","Production Report",$messageBody,$headers);
?>
Jan 2 '08 #10

P: n/a
In article
<e3**********************************@l32g2000hse. googlegroups.com>,
pa*****@excite.com wrote:
On Jan 2, 12:33 pm, Tim Streater <tim.strea...@dante.org.ukwrote:
In article
<fc01e709-a824-4662-a4f3-1d5fad0d5...@j20g2000hsi.googlegroups.com>,
[snip]

// now do the same for the other query
if (mysql_num_rows($result)) { // if there are results
// Add results from first query to email
while($row = mysql_fetch_array(mysql_query($sql))){
$messageBody .= "Editorial Date: " . $row['editorialdate'];
How do you expect this to work? Every time round the while loop, you do
the mysql_query again and fetch the first row of the results. You
shouldn't nest these calls.

I would also suggest a more tidy layout which will help you debug more
easily.

OK I am seeing this now, after adding this:
$result=mysql_query($sql);
It looks like my page is just in a loop, because it just continues to
try to load.

Looking at this code I think it will loop through and do a search on
$SQL until it does not find any other records matching, than it will
go down and do the same thing for $sql2 while there is something
there, all the time putting it into $messagebody

Am I close? What am I doing wrong?
No, this is going to loop forever. You did not read what I put
previously.

You are doing:

while($row = mysql_fetch_array(mysql_query($sql))){

as I said before, EACH TIME ROUND THE LOOP it is going to do the
mysql_query. The fetch will, each time, get you the first result from
the query so you never exit.

You should be doing something like this:

$result = mysql_query ($sql);
$numrows = mysql_num_rows ($result);
if ($numrows>0)
{
while ($row = mysql_fetch_array ($result))
{
// add first results
...
}
}
mysql_free_result ($result);

and then repeat ALL this for the other query.
Jan 2 '08 #11

This discussion thread is closed

Replies have been disabled for this discussion.