PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
sheka
Forum Newbie
Posts: 5 Joined: Fri May 15, 2009 1:50 pm
Post
by sheka » Fri May 15, 2009 2:36 pm
Hi there,
Thanks for so much info.
I can do with some help here please.
(am not a HTML professional, but can definately do copy and paste...
I just installed a php form, and I'm getting this notice,
Undefined variable on line 56. below is a portion including line 56.
I would also want the form not to send empty form entries.
Thanks for your help.
Code: Select all
// This line prevents a blank form being sent
$message = $message . "-- \Nature";
$message = stripslashes($message);
Last edited by
Benjamin on Sat May 16, 2009 10:19 am, edited 1 time in total.
Reason: Added [code=php] tags.
Defiline
Forum Commoner
Posts: 59 Joined: Tue May 05, 2009 5:34 pm
Post
by Defiline » Fri May 15, 2009 2:48 pm
I guess the form was written by lamer using register globals or without checking variables.
If the form has not been sent yet:
Code: Select all
<?php
if(isset($_POST['message'])) {
$message = $_POST['message']; // ...
}
?>
In case of register globals you should rewrite the form or extract the $_POST array.
sheka
Forum Newbie
Posts: 5 Joined: Fri May 15, 2009 1:50 pm
Post
by sheka » Sat May 16, 2009 1:57 am
Great
Should I just copy and replace the line with your code?
thanks.
Defiline
Forum Commoner
Posts: 59 Joined: Tue May 05, 2009 5:34 pm
Post
by Defiline » Sat May 16, 2009 5:10 am
You should post here your code.
I cannot correct anything until I will see the code.
Therefore I gave you some advices to correct your form (fix register globals [kill them], fix "isset").
sheka
Forum Newbie
Posts: 5 Joined: Fri May 15, 2009 1:50 pm
Post
by sheka » Sat May 16, 2009 6:50 am
I have copied from line 52 to 68. the area am getting the notice is 59.
Thanks for you time.
Code: Select all
// This line prevents values being entered in a URL
if ($_SERVER['REQUEST_METHOD'] != "POST"){exit;}
// This line prevents a blank form being sent
$message = $message . "-- \Nature";
$message = stripslashes($message);
$subject = "Safari enquiry";
$headers = "From: " . "\n" . "Return-Path: " . "\n" . "Reply-To: " . "\n";
mail($my_email,$subject,$message,$headers);
?>
Last edited by
Benjamin on Sat May 16, 2009 10:19 am, edited 1 time in total.
Reason: Added [code=php] tags.
Defiline
Forum Commoner
Posts: 59 Joined: Tue May 05, 2009 5:34 pm
Post
by Defiline » Sat May 16, 2009 7:06 am
Try to replace the given code with following:
Code: Select all
if(isset($_POST['message'])) {
$message = trim(stripslashes(htmlspecialchars($message)));
$message = $message.'-- \Nature';
$subject = "Safari enquiry";
$headers = "From: " . "\r\n" . "Return-Path: " . "\r\n" . "Reply-To: " . "\r\n";
mail($my_email,$subject,$message,$headers);
}
sheka
Forum Newbie
Posts: 5 Joined: Fri May 15, 2009 1:50 pm
Post
by sheka » Sat May 16, 2009 7:44 am
Now, I replaced the code, but am getting aparse syntax error. what should I change here:
Code: Select all
if(isset($_POST['message'])) {
$message = trim(stripslashes(htmlspecialchars($message)));
$message = $message.'-- \Nature';
$subject = "Safari enquiry";
$headers = "From: " . "\r\n" . "Return-Path: " . "\r\n" . "Reply-To: " . "\r\n";
mail($my_email,$subject,$message,$headers);
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML lang=en dir=ltr><HEAD><TITLE>¬ Natural Track Safaris | Adventures in the wilderness |</TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2600.0" name=GENERATOR>
<link href="ladies_files/stylesheet.css" rel="stylesheet" type="text/css">
<link href="bunia.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
body {
background-image: url(imgnew/back_red.jpg);
margin-top: 15px;
background-color: #703635;
background-repeat: repeat-x;
Last edited by
Benjamin on Sat May 16, 2009 10:20 am, edited 1 time in total.
Reason: Added [code=php] tags.
Defiline
Forum Commoner
Posts: 59 Joined: Tue May 05, 2009 5:34 pm
Post
by Defiline » Sat May 16, 2009 7:56 am
Did you close the last PHP tag before flushing of HTML ( ?> )
Code: Select all
<?php
/**
* Here is your PHP Code
*/
// ...........
?>
<html>
<head>
<title></title>
<!-- Etc. -->
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Sat May 16, 2009 10:21 am
@sheka - Use
Code: Select all
tags when posting code please. If you are unsure of how to do this, please contact me.
sheka
Forum Newbie
Posts: 5 Joined: Fri May 15, 2009 1:50 pm
Post
by sheka » Sun May 17, 2009 11:49 am
@Astions.
Yes, I would be glad.
Meanwhile guys, what should be the correct code here?
Code: Select all
while(list($key,$value) = each($_POST)){if(!(empty($value))){$set=1;}$message = $message . "$key: $value\n\n";} if($set!==1){header("location: $_SERVER[HTTP_REFERER]");exit;}
While I'm an amateur, this is the only part I have problem with the form.
Any help greatly appreciated.
Last edited by
Benjamin on Mon May 18, 2009 9:49 am, edited 1 time in total.
Reason: Added [code=php] tags.
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Mon May 18, 2009 9:49 am
sheka wrote: @Astions. Yes, I would be glad.
sheka wrote:
while(list($key,$value) = each($_POST)){if(!(empty($value))){$set=1;}$message = $message . "$key: $value\n\n";} if($set!==1){header("location: $_SERVER[HTTP_REFERER]");exit;}
Glad? To not do it? Next time you are getting a warning.