This topic is locked

Error on send email

4/16/2014 5:01:12 PM
PHPRunner General questions
B
btman author

Hi all
I am a complete PHP novice and I have an issue with sending an email with the record content after the deletion of the record. I have been trying several options but with no luck.
This is the code I have:
$from="info@blabla.com";

$msg="";

$subject="Training";
// modify the following SQL query to select fields you like to send

$rs = CustomQuery("select Name, Email, DatePicker, Les_dag, Les_tijden, ID from " . $strTableName ." where id=". $deleted_values["id"]);
if($data=db_fetch_array($rs))

{

foreach($data as $field=>$value)

$msg.= $field." : ".$value."\r\n";

$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));

if(!$ret["mailed"])

echo $ret["message"];
On deleting a record I get this error:
Technical Information

Errortype 256

Error description 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

URL rfsports.nl/mijn_trainingen/rfs_training_copy_list.php?

Error file /customers/1/4/7/rfsports.nl/httpd.www/mijn_trainingen/include/dbconnection.my.mysqli.php

Error line 42

SQL query select Name, Email, DatePicker, Les_dag, Les_tijden, ID from rfs_training_copy where id=
What am I doing wrong?
Any help is highly appreciated.

Thanks
Ben

S
stiven 4/16/2014

you can try this
is the field name id or ID??



$rs = CustomQuery("select Name, Email, DatePicker, Les_dag, Les_tijden, ID from " . $strTableName ." where id= '".$deleted_values["ID"]."'");//confirm ID field
B
btman author 4/17/2014



you can try this
is the field name id or ID??



$rs = CustomQuery("select Name, Email, DatePicker, Les_dag, Les_tijden, ID from " . $strTableName ." where id= '".$deleted_values["ID"]."'");//confirm ID field



Thanks for your reply.

The name field is ID but with this change the result is the same <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=74580&image=1&table=forumreplies' class='bbc_emoticon' alt=':(' />
It does find the ID and lists its content. These are the details of the error:
Call stack

File: line Function Arguments

0. include/dbconnection.my.mysqli.php:42 trigger_error 1. 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;

2. 256;

1. include/dbconnection.my.mysqli.php:42 db_query 1. select Name, Email, DatePicker, Les_dag, Les_tijden, ID from rfs_training_copy where id=;

2. mysqli;

2. include/dal.php:9 CustomQuery 1. select Name, Email, DatePicker, Les_dag, Les_tijden, ID from rfs_training_copy where id=;

3. include/rfs_training_copy_events.php:44 eventclass_rfs_training_copy->AfterDelete 1. ID=1202;

2. Array ( [Name] => Evelijne [Email] => Evelijnealessie@blabla.com [Les_dag] => Woensdag [DatePicker] => 2013-04-24 [Les_tijden] => 20.15 - 21.15 uur [ID] => 1202 ) ;

3. ;

4. ListPage_Simple;

4. classes/listpage.php:672 ListPage->deleteRecords N/A

5. classes/listpage.php:1916 ListPage->prepareForBuildPage N/A

6. rfs_training_copy_list.php:175 Global scope N/A



Any other ideas?
Thanks

Ben

A
Anapolis 4/17/2014

Your query doesn't look right to me -- is ID the primary key of the records you want to pull?
Is the table you are pulling from something like this?
Is the Field ID the primary id for the table?
ID | Name | Email | DatePicker | Les_dag | Les_tijden

1202 |Evelijne | Evelijnealessie@blabla.com | 2013-04-24 |Woensdag | 20.15 - 21.15 uur
if that is true then shouldn't your WHERE statement be "..where ID= " to match the same ID column name in your table?
If ID is the key to each row of rfs_training_copy table then the query should read "where ID= '".$deleted_values["ID"]."'");

S
stiven 4/17/2014

You might want to put that code on Before record deleted events page because if you do it after, wouldn't have the record been deleted already?
also this should work for you?



$from="info@blabla.com";

$msg="";

$subject="Training";
// modify the following SQL query to select fields you like to send

$rs = CustomQuery("SELECT Name, Email, DatePicker, Les_dag, Les_tijden, ID FROM " . $strTableName ." WHERE ID= '".$deleted_values["ID"]."'");
if($data=db_fetch_array($rs))

{

foreach($data as $field=>$value)

$msg.= $field." : ".$value."\r\n";

$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));

if(!$ret["mailed"])

echo $ret["message"];
B
btman author 4/17/2014



Your query doesn't look right to me -- is ID the primary key of the records you want to pull?
Is the table you are pulling from something like this?
Is the Field ID the primary id for the table?
ID | Name | Email | DatePicker | Les_dag | Les_tijden

1202 |Evelijne | Evelijnealessie@blabla.com | 2013-04-24 |Woensdag | 20.15 - 21.15 uur
if that is true then shouldn't your WHERE statement be "..where ID= " to match the same ID column name in your table?
If ID is the key to each row of rfs_training_copy table then the query should read "where ID= '".$deleted_values["ID"]."'");


Thank you Maverick, that did the trick.

The error message is gone.
But.... The email is not sent or at least it is not received <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=74587&image=1&table=forumreplies' class='bbc_emoticon' alt=':(' />
By the way, I just noticed that in my initial post the first 2 lines of the event code are missing which are:
global $conn,$strTableName;

$email="ben@blabla.nl";
Hope you have another idea.

Thanks for helping out
Ben

B
btman author 4/18/2014



You might want to put that code on Before record deleted events page because if you do it after, wouldn't have the record been deleted already?
also this should work for you?



$from="info@blabla.com";

$msg="";

$subject="Training";
// modify the following SQL query to select fields you like to send

$rs = CustomQuery("SELECT Name, Email, DatePicker, Les_dag, Les_tijden, ID FROM " . $strTableName ." WHERE ID= '".$deleted_values["ID"]."'");
if($data=db_fetch_array($rs))

{

foreach($data as $field=>$value)

$msg.= $field." : ".$value."\r\n";

$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));

if(!$ret["mailed"])

echo $ret["message"];



Thank you Stivens.

I have tried your suggestion to use Before record deleted, but unfortunately with the same result. Record is deleted, but no email is sent/received. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=74591&image=1&table=forumreplies' class='bbc_emoticon' alt=':(' />
Any suggestion of what the reason could be?
Thanks

Ben

A
Anapolis 4/18/2014

You might try this...since you are trying so MANY things <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=74596&image=1&table=forumreplies' class='bbc_emoticon' alt=':(' /> I have not tested:


global $conn;

$strTableName="rfs_training_copy";
$email="ben@blabla.nl";

$from="info@blabla.com";

$msg="";

$subject="Training";
$rs = CustomQuery("SELECT Name, Email, DatePicker, Les_dag, Les_tijden, ID FROM " . $strTableName ." WHERE ID= '".$deleted_values["ID"]."'");
$data=db_fetch_array($rs));
foreach($data as $key =>$value)

{

$msg.= $key." : ".$value."\r\n";

}

$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));
if($ret["mailed"])

echo "At last, at last! Email sent!";

else

{

echo "Geeze! Now WHAT??";

}


In your example --

foreach($data as $field=>$value)

$msg.= $field." : ".$value."\r\n";

$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));


It appears to me that first you must perform the loop enough times to grab the fields that your select query asked for and assemble a $msg string that puts each field name and its value on separate lines.
But you are not wanting to send a separate email for each field.
So you must leave the runner_email send function OUTSIDE of the "foreach" loop.
It must wait for the foreach { $msg gets assembled inside } to do its job.

THEN email the result. As in --

foreach($data as $key =>$value)

{

$msg.= $key." : ".$value."\r\n";

}

$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));


Also, since you want to see a final confirmation IF MAILED then you would not use if(!$ret["mailed"]).
The ! specifies that the message that follows is for a FAILURE, not for a Success. Or to state that more correctly -- the following code is going to say something if NO email gets sent. I prefer to think positively and get the good news first, if there IS good news... like one email out the door.

if(!$ret["mailed"])

echo $ret["message"];


And if you don't have a $message defined as in
$message ="Sorry to inform you of abject humiliating failure!";
you won't even get notified of your failure either.
Also, from my limited understanding you could not use the IF condition before the "foreach".