I think I have had a bug with a contact form which has been working for the last 2 months and now all of a sudden is says:
Fatal error: Cannot redeclare function (previously declared in...)
I have tried turning off the functions one by one but it just gives same error for next function down. My code is pretty standard. but, here it is (this is the beginning of the function. The code is long)
//Functions
function e($value)
{
return htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
}
//---------die dump function----------
function dd($data)
{
die(var_dump($data));
}
//Booking Page code (beginning)
<?php
require 'includes/config.php';
$name = $email = $date = $phone = $age = $tour = $message = '';
$errors = [];
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = e($_POST['name']);
$email = e($_POST['email']);
$tour = !empty($_POST['tour']) ? $_POST['tour'] : '';
$phone = e($_POST['phone']);
$date = e($_POST['date']);
$age = e($_POST['age']);
$message = e($_POST['message']);
$errors['name'] = checkNameBooking($name);
$errors['email'] = checkEmailBooking($email);
$errors['tour'] = checkTourBooking($tour);
$errors['date'] = checktimeBooking($date);
$errors['age'] = checkAgeBooking($age);
Related
Since the update to php7.1 I get an error on a contactform. Downgrading is not an option. Any solution? I tried some thing I found, but doesn't seem to work what I change.
The message I get is "Warning: illegal string offset in 'name'" and it does this for all the values in the form (name, email, message,...).
<?php
require_once("classes/phpmailer/class.phpmailer.php");
$smarty_mail = new Smarty;
$smarty_mail->template_dir = 'templates/mail';
$smarty_mail->compile_dir = 'pages/templates_c';
if ( isset($_POST['submit']) )
{
$error = '';
print_r($error);
if (!trim($_POST['name'])) $error['name']=true;
if (!check_email($_POST['email'])) $error['email']=true;
if (!trim($_POST['message'])) $error['message']=true;
if (!isset($_POST['privacypolicy'])) $error['privacypolicy']=true;
$_POST['name'] = stripslashes($_POST['name']);
$_POST['message'] = stripslashes($_POST['message']);
if (!$error)
{
$contact = $_POST;
$contact['ip'] = $_SERVER['REMOTE_ADDR'];
$contact['host'] = gethostbyaddr( $contact['ip']);
$smarty_mail->assign("contact", $contact);
$message = $smarty_mail->fetch("mail_contact.tpl.html");
$subject = "contactformulier";
if( sendemail(MAIL_FROM_NAME, MAIL_FROM, $_POST['name'], $_POST['email'], $subject, $message, "HTML", "", ""))
{
$smarty->assign("send", true);
}
}
$smarty->assign("error",$error);
$smarty->assign("set", $_POST);
}
$main_content_template = "contact.tpl.html";
?>
$error = '';
makes no sense. You're initializing $error as a string, but then you're accessing it as if it were an array:
$error['name']=true;
It should probably be
$error = array();
instead.
So i've got a table full of data. I have a page where i list all the contents of that able out through a while loop. Then the user can click a button on a record and it will generate an address label using the data it has and the generated label is done in a PDF. So that all works fine and dandy. However i was wondering is it possible to replace that button with an HTML Checkbox for each record to something like this
<input type="checkbox" name="<?php echo $recordTitle; ?>" />
<input type="hidden" name="<?php echo $recordID"; ?>" />
So this would allow people to select multiple records and then click one button and it would take all of those records and generate as many labels as it needed too. If this is possible, how would i process all of that, because i'd need to somehow loop through all the records the user has selected.
<?php
$eventSearch = $_POST['eventSearch'];
//Include Database connection
include '../includes/dbConnect.php';
foreach ($arr as &$value) {
$id = $value;
//Query Database for all customer info
$sql = "SELECT * FROM customerInterest WHERE `id` = '$value'";
$result = mysqli_query($dbLink, $sql);
$row = mysqli_fetch_assoc($result);
//require the document that creates the PDF
require('PDF_Label.php');
//Create a new PDF
$pdf = new PDF_Label('L7163');
$pdf->AddPage();
//assign the customer information to a variable
$sal = $row["salutation"];
$fn = $row["firstName"];
$ln = $row["lastName"];
$add1 = $row["contactAddress1"];
$add2 = $row["contactAddress2"];
$city = $row["contactAddressCity"];
$state = $row["contactAddressState"];
$post = $row["contactAddressPostcode"];
$country = $row["contactAddressCountry"];
if ($sal == "N/A") {
$sal = "";
}
if ($fn == "N/A") {
$fn = "";
}
if ($ln == "N/A") {
$ln = "";
}
if ($add1 == "N/A") {
$add1 = "";
}
if ($add2 == "N/A") {
$add2 = "";
}
if ($city == "N/A") {
$city = "";
}
if ($state == "N/A") {
$state = "";
}
if ($post == "N/A") {
$post = "";
}
if ($country == "N/A") {
$country = " ";
}
$add1 = $add1." ".$add2;
$post = str_replace(' ', '', $post);
$post = strtoupper($post);
$post = substr_replace($post, " ", 4, 0);
// Standard format
//create new page
// Print labels
$text = sprintf("%s\n%s\n%s\n%s %s",$sal." ".$fn." ".$ln, $add1, $city, $state, $post,$country);
$pdf->Add_Label($text);
}
//Output all the info
$pdf->Output();
?>
So the above contains the code i have now tried. I have posted the data to the PDf generating page (that is where all the code is from) and i keep getting the error (see below) and i cannot figure out why :/
Fatal error: Uncaught Error: Call to a member function Output() on null in /homepages/38/d735513801/htdocs/future/pdfGen/labelEX.php:80 Stack trace: #0 {main} thrown in /homepages/38/d735513801/htdocs/future/pdfGen/labelEX.php on line 80
In View.php file <?php echo $ticket->player_id ?> is working. But in controller.php it is not working. What is the correct syntax for Controller.php?
I am trying to use it here
'include_player_ids' => array('<?php echo $ticket->player_id ?>'),
The following is the sample code from controller file which are working properly
// Send Email
$email_template = $this->home_model->get_email_template_hook("ticket_reply", $lang);
if($email_template->num_rows() == 0) {
$this->template->error(lang("error_48"));
}
$email_template = $email_template->row();
if(isset($ticket->client_username)) {
$username = $ticket->client_username;
$email = $ticket->client_email;
$first_name = $ticket->first_name;
$last_name = $ticket->last_name;
} else {
$username = $ticket->guest_email;
$email = $ticket->guest_email;
$first_name = $ticket->guest_email;
$last_name = "";
}
In controller.php ,
$data['ticket'] = 'your data will be here';
In view.php,
'include_player_ids' => array($ticket->player_id),
Hope you understand.
Its already in php tags so you do not need to place <?php ?> again just assign variable directly
'include_player_ids' => array($ticket->player_id),
It should be
'include_player_ids' => array($ticket->player_id),
Please post the output of $ticket
I have read so many pages and am stuck on this for the past three hours now because it just won't work.
I keep getting Notice: Undefined index: firstname
here is the bulk of the segment that isn't working:
$errMsg = "";
function sanitise($data){
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
if (isset($_POST["firstname"]))
{
$firstname = $_POST["firstname"];
$firstname = sanitise($firstname);
if (!preg_match("/^[A-Za-z \-]+$/",$firstname))
{
$errMsg .= "First name must contain only letters or hyphens.<br/>";
}
if (strlen($firstname) > 40)
{
$errMsg .= "First name cannot be over 40 characters long.<br/>";
}
} else {
$errMsg .= "First name cannot be empty.<br/>";
$firstname = "";
}
if ($errMsg != "")
{
header("Location: fix_order.php?firstname=$firstname");
}
this is the code on fix_order.php where I want to access the variables.
$firstname = $_GET["firstname"];
echo "<p>firstname is $firstname .</p>";
I have tested the $firstname on the first page and it echo's the values just fine.
change your code to
$firstname = $_GET["errMsg"];
echo "<p>firstname is $firstname .</p>";
You can't access $firstname as this is the value not the key. errMsg is the key you should use.
Looks fine to me, it should work.
To get rid of the notice, you need to define variable by using isset()
$firstname = isset($_GET['firstname']) ? $_GET['firstname'] : '';
OR
if(isset($_GET['firstname'])) {
$firstname = $_GET['firstname'];
} else {
$firstname = '';
}
It seems like a pretty common problem but I can't see to find the answer to my problem. I have been getting the dreaded "Call to a member function verifyInput() on a non-object" fatal error.
<?php
// empty values
$name = $email = $topic = $message = "";
$nameErr = $emailErr = $topicErr = $messageErr = "";
// link the name tags in HTML
$name = $_POST['name'];
$email = $_POST['email'];
if ($_SERVER["REQUEST_METHOD"] == "POST") {
/* name if */
if (empty($_POST['name'])) {
$nameErr = " * Name is required";
} else {
$name = test_input($_POST["name"]);
}
/* email if */
if ( ! empty($_POST['email'])) {
if ($email->verifyInput($_POST['email'], 6)){
$fill['email'] = $_POST['email']; //$fill is the array of values passed
} else {
$emailErr = " * Email is incorrect - Try Again";
}
} else {
$emailErr = " * Email is required";
}
// Form content
$recipient = "generic#gmail.com";
$subject = "Contact Form";
$formcontent = "4 Days of Fun.ca -
\n\n\nFrom: $name \n\nEmail: $email \n\nSubject: $topic
\n\n\nMessage: $message";
$mailheader = "From: $email - Subject: $topic \r\n";
//function to send mail
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank you for contacting us, $name! \nWe will respond to you soon!";
}
//function for test_input
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
// Validation of Inputs
function verifyInput($input, $type){
if ($type == 0) $pattern = '/^1$/';//just the number 1
elseif ($type == 1) $pattern = '/^[0-9]+$/';//just integers
elseif ($type == 2) $pattern = '/^[A-Za-zÁ-Úá-úàÀÜü]+$/';//just letters
elseif ($type == 3) $pattern = '/^[0-9A-Za-zÁ-Úá-úàÀÜü]+$/';//integers & letters
elseif ($type == 4) $pattern = '/^[A-Za-zÁ-Úá-ú0-9àÀÜü\s()\/\'":\*,.;\-!?&#$#]{1,1500}$/';//text
elseif ($type == 5) $pattern = '/^[A-Za-zÁ-Úá-úàÀÜü0-9\']+[A-Za-zÁ-Úá-úàÀÜü0-9 \'\-\.]+$/';//name
elseif ($type == 6) $pattern = '/^.+#[^\.].*\.[a-z]{2,}$/';//e-mail
elseif ($type == 7) $pattern = '/^((\(0?[1-9][0-9]\))|(0?[1-9][0-9]))?[ -.]?([1-9][0-9]{3})[ -.]?([0-9]{4})$/';//brazilian phone
if (preg_match($pattern, $input) == 1) return true;
else return false;
}
?>
This is where the error is in question:if ($email->verifyInput($_POST['email'], 6)){ however I'm confused... I looked it up and everywhere states that the variable passed in ie $email may not be an object. But the variable is declared as an object here: $email = $_POST['email']; is it not? Or am I missing something big and obvious?
I just started learning PHP but I've got a lot of foundational knowledge with C++, so there are a lot of similarities I already get... This is not one of them.
Maybe I'm just not understanding the -> operator, or maybe it's a non-object because of something else?
Thanks in advance.
$email->verifyInput() would call the method (function) verifyInput() that is included in the class email, but here i can see that your function is not a member of any class, so if you need to call this fuction you just have to change:
if ($email->verifyInput($_POST['email'], 6)){...
to:
if (verifyInput($_POST['email'], 6)){...
And regarding your question about ->:
As i mentioned above -> is used after the instantiated class followed by the member or the method name. probably you need to read more about PHP, i would suggest this course, or you can jump directly to get a course about PHP OOP right here.