I have a function for WordPress:
<?php
function wpcf7_modify_this( $WPCF7_ContactForm ) {
$comment = "Row_1: " . $_POST['step1'] . ", Row_2: " . $_POST['step2'] . ", Row_3: " . $_POST['step3'] . ", Row_4: " . $_POST['step4'] . ", Row_5: " . $_POST['step51'] . $_POST['step52'] . $_POST['step53'] . $_POST['step54'] . $_POST['step55'] . $_POST['step56'] . ", Row_6: " . $_POST['step61'] . ", " . $_POST['step62'] . ", ". $_POST['step63'];
$roistatData = array(
'name' => isset($_POST['text-14']) ? $_POST['text-14'] : null,
'phone' => isset($_POST['tel-854']) ? $_POST['tel-854'] : null,
'comment' => $comment,
);
file_get_contents("https://cloud.com/api/add?" . http_build_query($roistatData));
}
add_action("wpcf7_before_send_mail", "wpcf7_modify_this");
?>
The data comes in this form (in one line):
I want like this :)
Please help me bring the data back to normal.
Sorry for my English :)
Thanks for helping.
Try this by Adding <br/> tag.
<?php
function wpcf7_modify_this( $WPCF7_ContactForm ) {
$comment = "Row_1: " . $_POST['step1'] . ",\n Row_2: " . $_POST['step2'] . ",\n Row_3: " . $_POST['step3'] . ",\n Row_4: " . $_POST['step4'] . ",\n Row_5: " . $_POST['step51'] . $_POST['step52'] . $_POST['step53'] . $_POST['step54'] . $_POST['step55'] . $_POST['step56'] . ",\n Row_6: " . $_POST['step61'] . ", " . $_POST['step62'] . ", ". $_POST['step63'];
$roistatData = array(
'name' => isset($_POST['text-14']) ? $_POST['text-14'] : null,
'phone' => isset($_POST['tel-854']) ? $_POST['tel-854'] : null,
'comment' => $comment,
);
file_get_contents("https://cloud.com/api/add?" . http_build_query($roistatData));
}
add_action("wpcf7_before_send_mail", "wpcf7_modify_this");
?>
Use <br/> or \n :
<?php
function wpcf7_modify_this( $WPCF7_ContactForm ) {
$comment = "Row_1: " . $_POST['step1'] . ",<br/> Row_2: " . $_POST['step2'] . ",<br/> Row_3: " . $_POST['step3'] . ",<br/> Row_4: " . $_POST['step4'] . ",<br/> Row_5: " . $_POST['step51'] . $_POST['step52'] . $_POST['step53'] . $_POST['step54'] . $_POST['step55'] . $_POST['step56'] . ",<br/> Row_6: " . $_POST['step61'] . ", " . $_POST['step62'] . ", ". $_POST['step63'];
$roistatData = array(
'name' => isset($_POST['text-14']) ? $_POST['text-14'] : null,
'phone' => isset($_POST['tel-854']) ? $_POST['tel-854'] : null,
'comment' => $comment,
);
file_get_contents("https://cloud.com/api/add?" . http_build_query($roistatData));
}
add_action("wpcf7_before_send_mail", "wpcf7_modify_this");
?>
Related
i have an html form , when user submits the data, the data goes into database, this was working fine until i added one more thing, i added mail function to send the mail after the data is submitted. my code is like below:
<?php
error_reporting(0);
session_start();
require('db_config.php');
if (isset($_POST['submit'])) {
$name = $_FILES['Photo']['name'];
list($txt, $ext) = explode(".", $name);
$image_name = time() . "." . $ext;
$tmp = $_FILES['Photo']['tmp_name'];
$shame = $_FILES['paymentphoto']['name'];
list($txts, $exts) = explode(".", $shame);
$receipt_name = time() . "." . $ext;
$tmps = $_FILES['paymentphoto']['tmp_name'];
if (move_uploaded_file($tmp, 'uploads/' . $image_name) && move_uploaded_file($tmps, 'receipt/' . $receipt_name)) {
$sql = "INSERT INTO members (firstname, lastname, image, company, designation, addressone, addresstwo, aadhar, city, state, pin, pan, rnameone, rnametwo, mobile, alternate, email, experience, businessdate, companyregistration, gstin, servicesoffered, fee, mode, receipt) VALUES ('" . $_POST['first_name'] . "','" . $_POST['last_name'] . "' , '" . $image_name . "','" . $_POST['company'] . "', '" . $_POST['designation'] . "','" . $_POST['address'] . "', '" . $_POST['address2'] . "', '" . $_POST['aadhaar'] . "', '" . $_POST['city'] . "', '" . $_POST['state'] . "', '" . $_POST['pin'] . "', '" . $_POST['pan'] . "', '" . $_POST['recommended'] . "', '" . $_POST['recommended2'] . "','" . $_POST['mobile'] . "', '" . $_POST['alternate'] . "', '" . $_POST['email'] . "', '" . $_POST['experience'] . "', '" . $_POST['date'] . "', '" . $_POST['registration'] . "', '" . $_POST['gst'] . "', '" . $_POST['services'] . "', '" . $_POST['fee'] . "', '" . $_POST['payment'] . "', '" . $receipt_name . "' )";
$mysqli->query($sql);
$to = "teiamembers#gmail.com"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$headers = "From:" . $from . "\nMIME-Version: 1.0\nContent-Type: text/html; charset=utf-8\n";
$headers2 = "From:" . $to;
$subject = "TEIA Membership Registration Request";
$subject2 = "TEIA Membership Request";
$message = $first_name . " has requested for TEIA Registration. Full Name:" . " " . $first_name . " " . $last_name . "<br>" . "Email:" . $from . "<br>" . "Mobile:" . " " . $_POST['mobile'] . "<br>" . "Company Name:" . " " . $_POST['company'] . "<br>" . "Designation" . " " . $_POST['designation'] . "<br>" . "Residence Address:" . " " . $_POST['address'] . "<br>" . "Office Address:" . " " . $_POST['address2'] . "<br>" . "Aadhaar:" . " " . $_POST['aadhaar'] . "<br>" . "City:" . " " . $_POST['city'] . "<br>" . "State:" . " " . $_POST['state'] . "<br>" . "Pin:" . " " . $_POST['pin'] . "<br>" . "Pan:" . " " . $_POST['pan'] . "<br>" . "Reference:" . " " . $_POST['recommended'] . "<br>" . "Alternate Number:" . " " . $_POST['alternate'] . "<br>" . "Experience:" . " " . $_POST['experience'] . "<br>" . "Aadhaar:" . " " . $_POST['aadhaar'] . "<br>" . "Date of Business Setup:" . " " . $_POST['date'] . "<br>" . "Company Registration Number:" . " " . $_POST['registration'] . "<br>" . "GSTIN:" . " " . $_POST['gst'] . "<br>" . "Services Offered:" . " " . $_POST['services'] . "<br>" . "Fee Paid:" . " " . $_POST['fee'] . "<br>" . "Payment Mode:" . " " . $_POST['payment'] . "<br>";
$message2 = "Your request for TEIA Membership Received. We will contact you Shortly. ";
mail($to, $subject, $message, $headers);
mail($from, $subject2, $message2, $headers2); // sends a copy of the message to the sender
if ($mysqli) {
$msg = "Your Request For Membership Registration Sent Successfully";
}
}
}
?>
now the problem is when the user submits the form, the mail is working properly, but the values are not going to database, can anyone please tell me what could be wrong here, thanks in advance
TAKE CARE OF SQL INJECTION first.
Some amount of checking is necessary all the time. At the very least...this one.
if($mysqli->query($sql)) { fine } else { error }
And in the "error" part of above, if you would have included error number and actual message, you yourself might have found the answer.
Main doubt I have is...you have some unique column and the insert did not happen as it did appear in database earlier.
Also, better to use an id int unique auto_increment for several purposes.
Secondly, you should have created $mailstatus and have checked the same and not mysqli for this message.
if ($mailstatus) {
$msg = "Your Request For Membership Registration Sent Successfully";
}
I am trying to make a button on a page that prints out data from the database and then you can press 2 different buttons, one that deletes them from the database and the other one inserts it into another table in the database and deletes the data from the database, but it keeps inserting it twice into the new table and I have no clue why, this here prints out the data and session variables + buttons:
if(!isset($_POST['orderby'])) {
foreach ($requests as $row) {
echo "<div class='requests'>" . "<li class='refunds'>" . "Palauttajan nimi: ".
$row['customer_name'] . "</br>" ."Palautettavat tuotteet: ".$row['product_name']."<br> "."Määrä: ".
$row['product_qty'] . " "
. "<br>Kommentti: " . $row['comment'] . "<br> " . "Hinta: " . $row['refund_total'] . "€ " .
"<br>" . "Päivämäärä: " . $row['request_date'] . " " .
"<a class='right' href='admin-page?deleteid=" . $row['request_id'] . "'>Hylkää</a></li>" .
"<li class='refundaccepts'><a href='admin-page?acceptid=" . $row['request_id']
. "'>Hyväksy</a></li>" . "</div>";
$_SESSION['custname'] = $row['customer_name'];
$_SESSION['prodname'] = $row['product_name'];
}
} else {
foreach ($pergele as $row) {
echo "<div class='requests'>" . "<li class='refunds2'>" . "Palauttajan nimi: ".
$row['customer_name'] . "</br>" ."Palautettavat tuotteet: ".$row['product_name']."<br> "."Määrä: ".
$row['product_qty'] . " "
. "<br>Kommentti: " . $row['comment'] . "<br> " . "Hinta: " . $row['refund_total'] . "€ " .
"<br>" . "Päivämäärä: " . $row['request_date'] . " " .
"<a class='right' href='admin-page?deleteid=" . $row['request_id'] . "'>Hylkää</a></li>" .
"<li class='refundaccepts'><a href='admin-page?acceptid=" . $row['request_id']
. "'>Hyväksy</a></li>" . "</div>";
$_SESSION['custname'] = $row['customer_name'];
$_SESSION['prodname'] = $row['product_name'];
}
}
and this should insert it into the database once and delete the data from the old table:
if(isset($_GET['acceptid'])) {
$accept = $_GET['acceptid'];
$custname = $_SESSION['custname'];
$prodname = $_SESSION['prodname'];
/* Query to do whatever here */
$wpdb->insert("wp_acceptedrequests", [
"customer_name" => "$custname",
"name_product" => "$prodname",
"date" => date("Y/m/d/G:i:sa") ,
]);
$wpdb->query("DELETE FROM wp_refundrequests WHERE request_id = $accept");
}
What makes them insert twice and how do I prevent it from doing that?
I just ran into a similar situation where $wpdb inserts where being duplicated.
In my case it was happening if I was authenticated and browser inspector was open.
Nerd question, apologies, Below function works when there is only single if statement but when i add multiple if statements, it won't work, as far i know about php currently i used elseif statement but also id didn't worked
function NewNoticeMSG($insert_id) {
$notice = $this->CI->notification_model->get_notice($insert_id);
$stu_setting = $this->CI->setting_model->getSkoolInfo();
if ($notice['visible_student'] == 'Yes') {
$students = $this->CI->student_model->get_all_students();
foreach($students as $student) {
$MSG = "Dear Student, NOTICE " . $notice['date'] . ": " . $notice['title'] . " . Thank You, " . $stu_setting['name'] . ".";
$content = 'AUTH_KEY=' . rawurlencode($this->AUTH_KEY) .
'&message=' . rawurlencode($MSG) .
'&senderId=' . rawurlencode($this->senderId) .
'&routeId=' . rawurlencode($this->routeId) .
'&mobileNos=' . rawurlencode($student['mobileno']) .
'&smsContentType=' . rawurlencode($this->smsContentType);
$smsglobal_response = $this->sendSMS($content);
}
}
if ($notice['visible_parent'] == 'Yes') {
$students = $this->CI->student_model->get_all_students();
foreach($students as $student) {
$MSG = "Dear Parent, NOTICE " . $notice['date'] . ": " .
$notice['title'] . " . Thank You, " . $stu_setting['name'] . ".";
$content = 'AUTH_KEY=' . rawurlencode($this->AUTH_KEY) .
'&message=' . rawurlencode($MSG) .
'&senderId=' . rawurlencode($this->senderId) .
'&routeId=' . rawurlencode($this->routeId) .
'&mobileNos=' . rawurlencode($student['guardian_phone']) .
'&smsContentType=' . rawurlencode($this->smsContentType);
$smsglobal_response = $this->sendSMS($content);
}
}
if ($notice['visible_teacher'] == 'Yes') {
$teachers = $this->CI->teacher_model->get_all_teachers();
foreach($teachers as $teacher) {
$MSG = "Dear Teacher, NOTICE " . $notice['date'] . ": " . $notice['title'] . " . Thank You, " . $stu_setting['name'] . ".";
$content = 'AUTH_KEY=' . rawurlencode($this->AUTH_KEY) .
'&message=' . rawurlencode($MSG) .
'&senderId=' . rawurlencode($this->senderId) .
'&routeId=' . rawurlencode($this->routeId) .
'&mobileNos=' . rawurlencode($teacher['phone']) .
'&smsContentType=' . rawurlencode($this->smsContentType);
$smsglobal_response = $this->sendSMS($content);
}
}
}
how should i do that??
Firstly you need to on error reporting then you should print array what you get then use isset and !empty in if statement,
For example:-
if (isset($notice['visible_student']) &&
!empty($notice['visible_student']) && $notice['visible_student'] ==
'Yes')
instead of this, "if ($notice['visible_student'] == 'Yes')"
Hope it will help you!
Please Try with the :
function NewNoticeMSG($insert_id) {
$notice = $this->CI->notification_model->get_notice($insert_id);
$stu_setting = $this->CI->setting_model->getSkoolInfo();
if (isset($notice['visible_student']) && $notice['visible_student'] == 'Yes') {
$students = $this->CI->student_model->get_all_students();
foreach($students as $student) {
$MSG = "Dear Student, NOTICE " . $notice['date'] . ": " . $notice['title'] . " . Thank You, " . $stu_setting['name'] . ".";
$content = 'AUTH_KEY=' . rawurlencode($this->AUTH_KEY) .
'&message=' . rawurlencode($MSG) .
'&senderId=' . rawurlencode($this->senderId) .
'&routeId=' . rawurlencode($this->routeId) .
'&mobileNos=' . rawurlencode($student['mobileno']) .
'&smsContentType=' . rawurlencode($this->smsContentType);
$smsglobal_response = $this->sendSMS($content);
}
}
if (isset($notice['visible_parent']) && $notice['visible_parent'] == 'Yes') {
$students = $this->CI->student_model->get_all_students();
foreach($students as $student) {
$MSG = "Dear Parent, NOTICE " . $notice['date'] . ": " .
$notice['title'] . " . Thank You, " . $stu_setting['name'] . ".";
$content = 'AUTH_KEY=' . rawurlencode($this->AUTH_KEY) .
'&message=' . rawurlencode($MSG) .
'&senderId=' . rawurlencode($this->senderId) .
'&routeId=' . rawurlencode($this->routeId) .
'&mobileNos=' . rawurlencode($student['guardian_phone']) .
'&smsContentType=' . rawurlencode($this->smsContentType);
$smsglobal_response = $this->sendSMS($content);
}
}
if (isset($notice['visible_teacher']) && $notice['visible_teacher'] == 'Yes') {
$teachers = $this->CI->teacher_model->get_all_teachers();
foreach($teachers as $teacher) {
$MSG = "Dear Teacher, NOTICE " . $notice['date'] . ": " . $notice['title'] . " . Thank You, " . $stu_setting['name'] . ".";
$content = 'AUTH_KEY=' . rawurlencode($this->AUTH_KEY) .
'&message=' . rawurlencode($MSG) .
'&senderId=' . rawurlencode($this->senderId) .
'&routeId=' . rawurlencode($this->routeId) .
'&mobileNos=' . rawurlencode($teacher['phone']) .
'&smsContentType=' . rawurlencode($this->smsContentType);
$smsglobal_response = $this->sendSMS($content);
}
}
}
I keep getting this error
Unknown column 'Hello' in 'field list'
when I execute this code
$sql = "INSERT INTO installs (date,addedBy,customer,reg,vehMake,vehModel,colour,mileage,location,tracker,serial,sim,extr as,satnav,input1,input2,output,comments) VALUES (" . $date . ", " . $addedBy . ", " . $customer . ", " . $reg . ", " . $vehMake . ", " . $vehModel . ", " . $colour . ", " . $mileage . ", " . $location . ", " . $tracker . ", " . $serial . ", " . $sim . ", " . $extras . ", " . $satnav . ", " . $input1 . ", " . $input2 . ", " . $output . ", " . $comments . ")";
$result = $connect->query($sql) or die($connect->error);
replace this
(' . "Hello" . ', ' . 2 . ', ' . 3 . ', ' . 4 . ', ' . 4 . ', ' . 5 . ', ' . 6 . ', ' . 7 . ', ' . 8 . ', ' . 9 . ', ' . 10 . ', ' . 11 . ', ' . 12 . ', ' . 13 . ', ' . 14 . ', ' . 15 . ', ' . 16 . ', ' . 17 . ')';
by
("Hello", 2 ,3, 4,4,5,6,7,8,9,10,11,12, 13,14,15,16,17)';
EDIT:
replace this
(" . $date . ", " . $addedBy . ",..........
by
('$date', '$addedBy',...........
or this
('" . $date . "', '" . $addedBy . "',..........
Hello needs to be enclosed in single quotes. Escape the quotes like this:
$sql = 'INSERT INTO installs
(date,addedBy,customer,reg,vehMake,vehModel,colour,
mileage,location,tracker,serial,sim,extras,satnav,
input1,input2,output,comments)
VALUES
(\'' . "Hello" . '\', ' . 2 . ', ' . 3 . ', ' . 4 . ', ' . 4 . ',
' . 5 . ', ' . 6 . ', ' . 7 . ', ' . 8 . ', ' . 9 . ',
' . 10 . ', ' . 11 . ', ' . 12 . ', ' . 13 . ', ' . 14 . ', ' . 15 . ',
' . 16 . ', ' . 17 . ')';
One likely explanation for this behavior is that sql_mode inclues (or enables) ANSI_QUOTES.
SELECT ##SESSION.sql_mode
If ANSI_QUOTES is enabled, then double quotes can't be used around string literals; whatever is between the double quotes will be interpreted as an identifier (e.g. column name). If ANSI_QUOTES is enabled, then string literals should be enclosed in single quotes.
For the love of all that is good and beautiful in this world, just use prepared statements with placeholders, to avoid issues with quotes and to thwart SQL injection vulnerabilities.
e.g.
$sql = "INSERT INTO installs (date,addedBy,customer, ...)
VALUES ( :date, :addedBy, :customer, ...)";
$sth = $connect->prepare($sql);
$sth->execute(array(':date' => $date, ':addedBy' => $addedBy, ':customer' => $customer, ... ));
The above code is designed to display info stored in sql table. everything is corresponding to the titles in the table and in the correct order. however the page it is from is only displaying the first 2 columns and not the others. everything looks as if it is in order to me. is my statement wrong?
<?php
$con=mysqli_connect("xxx","y","y","yyyy");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM tripdata ");
while($row = mysqli_fetch_array($result))
{
echo $row['trip_id'] . " " . $row['image'] . " " . $row['date'] . " " . $row['destination'] . " " . $row['hl'] . " " . $row['cost'] . " " . $row['blurb'] . " " . $row['whatinc'] . " " . $row['whatopt'] . " " . $row['itin'] . " " . $row['depinfo'] . " " . $row['ppcode'];
echo "<br>";
}
mysqli_close($con);
?>
maybe you can try using assoc
while($row = mysqli_fetch_assoc($result))
{
echo $row['trip_id'] . " " . $row['image'] . " " . $row['date'] . " " . $row['destination'] . " " . $row['hl'] . " " . $row['cost'] . " " . $row['blurb'] . " " . $row['whatinc'] . " " . $row['whatopt'] . " " . $row['itin'] . " " . $row['depinfo'] . " " . $row['ppcode'];
echo "<br>";
}
i usual use this and no problem
assoc is index name based on field name
but array is based on number (0, 1, 2, 3)
Strange. Try do loop instead:
do {
echo $row['trip_id'] . " " . $row['image'] . " " . $row['date'] . " " . $row['destination'] . " " . $row['hl'] . " " . $row['cost'] . " " . $row['blurb'] . " " . $row['whatinc'] . " " . $row['whatopt'] . " " . $row['itin'] . " " . $row['depinfo'] . " " . $row['ppcode'];
echo "<br>";
} while($row = mysqli_fetch_array($result));