problem with this code..??
problem with this code..??
am 02.01.2008 15:16:16 von paul814
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:
$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("paul@company.com","Production Report",$messageBody);
mysql_close($con); //closes the connection to the DB
?>
thanks for any help
Re: problem with this code..??
am 02.01.2008 15:26:08 von paul814
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:
>
> $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
Re: problem with this code..??
am 02.01.2008 15:30:02 von paul814
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:
> >
> > $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:
$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("paul@company.com","Production Report",$messageBody);
?>
Re: problem with this code..??
am 02.01.2008 15:53:48 von Tim Streater
In article
<52120bfd-b2a0-4b8f-a3e6-f96cf2793714@e50g2000hsh.googlegroups.com>,
paul814@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:
> > >
> > > $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:
>
> $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("paul@company.com","Production Report",$messageBody);
?>
Re: problem with this code..??
am 02.01.2008 18:09:43 von paul814
On Jan 2, 9:53 am, Tim Streater wrote:
> 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:
> > > >
> > > > $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:
> >
> > $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:
$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: Prod.Report_PREPRESS@company.com";
mail("paul@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
Re: problem with this code..??
am 02.01.2008 18:18:39 von Courtney
paul814@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:
>
> $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_PREPRESS@company.com";
> mail("paul@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
Re: problem with this code..??
am 02.01.2008 18:23:46 von paul814
On Jan 2, 12:18 pm, The Natural Philosopher wrote:
> 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:
> >
> > $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?
Re: problem with this code..??
am 02.01.2008 18:33:02 von Tim Streater
In article
,
paul814@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:
>
> $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.
Re: problem with this code..??
am 02.01.2008 18:37:18 von Tim Streater
In article
<19822ae9-b6c1-424a-92b1-cbf5d754d851@x69g2000hsx.googlegroups.com>,
paul814@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?
Re: problem with this code..??
am 02.01.2008 18:40:57 von paul814
On Jan 2, 12:33 pm, Tim Streater wrote:
> In article
> ,
>
> 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:
> >
> > $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:
$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: Prod.Report_PREPRESS@company.com";
mail("paul@company.com","Production Report",$messageBody,$headers);
?>
Re: problem with this code..??
am 02.01.2008 20:22:57 von Tim Streater
In article
,
paul814@excite.com wrote:
> On Jan 2, 12:33 pm, Tim Streater wrote:
> > In article
> > ,
[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.