This topic is locked

Inserting into new table

10/9/2018 10:02:16 PM
PHPRunner General questions
A
Andrew S author

Hi all
Hopefully someone can point me in the right direction with the following problem which I have spent hours trying to figure out.
I have a table which is only displayed as a list - no add or edit facility is required. From list, users are able to select (using checkbox next to view icon) multiple records of interest. Once selected, by hitting custom button with server event code, an email is sent to the site owner and also the customer and this all works fine.
The code used and working is as follows:
$email_msg = "";
$i=1;
while($data = $button->getNextSelectedRecord())
{

$email_msg.= "User ID: ".$_SESSION[biouserID]."\r\n";;

$email_msg.= "Number: ".($i++)."\r\n";

$email_msg.= "Record ID: ".$data["ID"]."\r\n";

$email_msg.= "Case Number: ".$data["Case_Number"]."\r\n";
$email_msg.= "Description: ".$data["Description"]."\r\n";

$email_msg.= "\r\n";
$email_msg.= "\r\n";
}
//send email
$email = "@.co.uk";
$subject = $_SESSION[UserName] . " " . "(".$_SESSION[email].")". " Interested in the following: ";
runner_mail(array('to' => $email, 'cc' => $_SESSION[email], 'subject' => $subject, 'body' => $email_msg));
}
and this is text of the email received from the above :
User ID: 1

Number: 1

Record ID: 1

Case Number: BM08-000001

Description: bone marrow biopsy with aspiration is a 1.5 cm red tan bone core biopsy (A1); bone marrow aspirate in formalin is filtered for spicules (A2). Also received are 13 bone marrow aspirate smears 0 touch preps 1 peripheral smear 0 EDTA bone marrow aspirate 0 sodium heparin bone marrow aspirate and a CBC result. PRZ/vk/ejs
========================================
What I am now trying to achieve is that as well as sending an email, I want to record the UserName and Case Number into a new table in the same database named Enquiries so that the site owner can keep record of who is interested in what.
I have found an article on how to UPDATE multiple records and tried changing to INSERT
while ( $data = $button->getNextSelectedRecord() ) {
// set ReportsTo field to 'Bob Smith'
$sql = "INSERT INTO Enquiries (BioID, Case_Number) values ($data['ID'],$data['Case_Number'])";
CustomQuery($sql);
}
However, this does not work but also does not give an error and the email side stops working.
Any help greatly appreciated (phprunner 9.8)
Thank you

Andrew

admin 10/10/2018

Your code that builds SQL query is incorrect. You need to learn how to properly concatenate strings in PHP so you can build a proper query.
Check second code example at https://xlinesoft.com/phprunner/docs/check_if_specific_record_exists.htm, it shows an example of concatenation in PHP.
Another and a better option is to use Database API, easier syntax and no need to mess with writing SQL queries directly:

https://xlinesoft.com/phprunner/docs/db_insert.htm