Jump to content


PHP 4 to PHP 5 Help


2 replies to this topic

#1 davidk20

    Young Padawan

  • Members
  • Pip
  • 33 posts
  • Gender:Male

Posted 28 November 2008 - 05:39 AM

Hello people

I have very little knowledge in PHP and am getting confused. I am having to change a PHP script because the webserver is changing from PHP 4 to just PHP 5. The script had been working fine on PHP 4 but have a error code when running PHP 5.

The script is a simple mailto form for people to key in there information and send it to me via email, There are parts that must be filled otherwise it will not send and also on the email address it looks for the "@ and ." signs. With PHP 5 the email is still sent but it also shows a error which is not good for the user as they my think it has not send and not good for me.

When the customer has filled in there information and submits it the next page that loads looks like this (please note the line numbers will not be the same as this scripy has been taken from a web template)

---------------------------------------------------------------------------------------------------------------
Notice: Undefined variable: fail in /vhost/vhost8/b/a/s/domain.co.uk/www/onlineform.php on line 192


Thank you, NAME, for sending us your details. We will contact you shortly and help you with your query.

The details you provided us are as follows:


NAME
EMAIL@EMAIL.EMAIL
TELEPHONE


Notice: Undefined variable: msg in /vhost/vhost8/b/a/s/domain.co.uk/www/onlineform.php on line 201
---------------------------------------------------------------------------------------------------------------

The form code looks like this
contact.php
				<form action="onlineform.php" method="POST" class="style2">
  <br />
  <table width="99%" border="0" cellpadding="1" cellspacing="1">
	<tr>
	  <td width="25%" class="font">Name:</td>
	  <td width="35%" class="font"><input name="name" type="text" id="name" tabindex="1" size="17" />
		  <span class="style4">*</span></td>
	  <td width="40%" class="font">How can we help?</td>
	</tr>
	<tr>
	  <td class="font">Company:</td>
	  <td class="font"><input name="company" type="text" id="company" tabindex="2" size="17" /></td>
	  <td rowspan="8" valign="top" class="style20 style20"><textarea name="comments" cols="25" rows="11" id="comments" tabindex="8"></textarea></td>
	</tr>
	<tr>
	  <td class="font">Address line 1: </td>
	  <td class="font"><input name="address1" type="text" id="address1" tabindex="3" size="17" /></td>
	</tr>
	<tr>
	  <td class="font">Address line 2: </td>
	  <td class="font"><input name="address2" type="text" id="address2" tabindex="4" size="17" /></td>
	</tr>
	<tr>
	  <td class="font">City/Town: </td>
	  <td class="font"><input name="town" type="text" id="town" tabindex="4" size="17" /></td>
	</tr>
	<tr>
	  <td class="font">Postcode: </td>
	  <td class="font"><input name="postcode" type="text" id="postcode" tabindex="4" size="17" /></td>
	</tr>
	<tr>
	  <td class="font">Telephone: </td>
	  <td class="font"><input name="phone" type="text" id="phone" tabindex="4" size="17" />
		  <span class="style4">* </span></td>
	</tr>
	<tr>
	  <td class="font">Fax: </td>
	  <td class="font"><input name="fax" type="text" id="fax" tabindex="4" size="17" />
	  </td>
	</tr>
	<tr>
	  <td class="font">Email: </td>
	  <td class="font"><input name="email" type="text" id="email" tabindex="4" size="17" />
		  <span class="style4"> * </span></td>
	</tr>
	<tr>
	  <td>&nbsp;</td>
	  <td><input type="submit" name="Submit" value="Submit Form" />
	  </td>
	  <td valign="top" class="font">&nbsp;</td>
	</tr>
  </table>
  <blockquote>
	<p align="left"> Any box marked with a ( <span class="style4">*</span> ) must be filled in.<br />
</p>
				  </blockquote>
				</form>

And the part that submits the information via email looks like this
onlineform.php
 <?
/* Sets variable equal to what the user put in the "name" element of your form, and trims it. */
$user_name = trim($_POST['name']);
/* if ($user_name is not equal to 0)... By not equal to 0, I mean, is there actually something there */
if(!$user_name){
	echo('<p><b>ERROR</b></p>You did not enter your <b>Name</b>, Please click back on your browser and try again.<p>');
	$fail="1";
}

/* if (the position of the @ sign in $_POST['email'] is not 0)... */
if(strpos($_POST['email'], '@')){
	echo '';
}else{
	/* @ was not found */
	echo('<p><b>ERROR</b></p>You entered an invalid <b>Email address</b>, Please click back on your browser and try again.<p>');
	$fail="1";
}

/* Sets variable equal to what the user put in the "name" element of your form, and trims it. */
$user_name = trim($_POST['phone']);
/* if ($user_name is not equal to 0)... By not equal to 0, I mean, is there actually something there */
if(!$user_name){
	echo('<p><b>ERROR</b></p>You did not enter your <b>Contact Phone Number</b>, Please click back on your browser and try again.<p>');
	$fail="1";

}

if (!$fail){
echo "<p>Thank you, <b>$_POST[name]</b>, for sending us your details. We will contact you shortly and help you with your query.</p>";
echo "<p>The details you provided us are as follows: <p>
 <blockquote>
   <b>$_POST[name]<br>
   	  $_POST[email]<br>  
	  $_POST[phone]<br>
 </blockquote>";
//start building the mail string
$msg .= "Name:				$_POST[name]\n";
$msg .= "Company:				$_POST[company]\n";
$msg .= "Address Line1:			$_POST[address1]\n";
$msg .= "Address Line2:			$_POST[address2]\n";
$msg .= "City/Town:				$_POST[town]\n";
$msg .= "Postcode:				$_POST[postcode]\n";
$msg .= "Phone number:			$_POST[phone]\n";
$msg .= "Fax number:			$_POST[fax]\n";
$msg .= "E-Mail address:			$_POST[email]\n";
$msg .= "Comments:				$_POST[comments]\n";
//set up the mail
$recipient = "sales@domain.co.uk";
$subject = "WEBSITE FORM";
$mailheaders = "From: WEBSITE <onlineform@domain.co.uk> \n";
$mailheaders .= "Reply-To: $_POST[email]";
//send the mail
mail($recipient, $subject, $msg, $mailheaders);
}
?>

If anybody has any spare time to help me with this it would be much appreshated. Im hoping it is a simple fix as it was working fine with PHP 4 but not with PHP 5 :).

Thanks for any help

#2 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 28 November 2008 - 01:11 PM

That's not an error you need to be worried about. Just turn off notices in your php script:

http://php.net/error_reporting (example #1, function 4, line 15)

You can also checkout the following FAQ for more information on the difference between php 4 and 5
http://php.net/manual/en/faq.migration5.ph...ration5.changes

#3 davidk20

    Young Padawan

  • Members
  • Pip
  • 33 posts
  • Gender:Male

Posted 01 December 2008 - 06:54 AM

Thanks rc69, the pages you linked me are a little over my head but after googleing "turning off notice reports in php" i found a small easy fix.

<?php
error_reporting(0);
?>

Onces again thank you :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users