Contact form not working properly

Hi

I have set up a very primitive web form. Unfortunately when it comes up some of the php code the php code can be seen in the contact form boxes like this:

<?php echo htmlspecialchars($_POST[‘text’],ENT_QUOTES); ?>

Can anyone help me as to where I am going wrong here?

The page can be seen here:

http://www.solutionsoinlaw.co.uk/contact2.html

The code is as follows:

<?php require_once("connect/connection.php");
require_once("includes/functions.php");
if(isset($_POST['submit'])){
$errors = array();
$requiredfields = array('first_name'=> 'Please enter your FIRST NAME','surname'=> 'Please enter your SURNAME','email'=> 'Please enter your E Mail ADDRESS','text'=> 'Please enter your current needs');
foreach($requiredfields as $fieldname => $requiredfieldsmessage){
if(!isset($_POST[$fieldname]) || empty($_POST[$fieldname]) || strlen(trim($_POST[$fieldname])) == 0) {
$errors[] = $requiredfieldsmessage;
}
}
 if(count($errors) == 0){

 $_POST = array_map('mysqli_prep', $_POST);

$first_name =  mysqli_prep($_POST['first_name']);
$surname =  mysqli_prep($_POST['surname']);
$email =   mysqli_prep($_POST['email']);
$text =  mysqli_prep($_POST['text']);
$query = "INSERT INTO form (first_name,surname,email,text)Values('{$first_name}','{$surname}','{$email}','{$text}')";
$result = mysqli_query($connection, $query);
$message="A contact form has been completed on web-writer-articles.co.uk";
$subject="Ghostwriter contact form";
$subject2="Nick Cassells: Ghostwriter and copywriter";
$message2="Thank you for contacting me concerning your copywriting or ghostwriting needs. I will contact you as soon as possible. Thank you!<br> With best regards,<br> Nick Cassells";
$email2=$email;
mail('njc27@sky.com',$subject,$message);
mail($email2, $subject2, $message2);
header('Location: brief_return.php');
exit;
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>

<head>

<title>Contact Solutions in Law - Immigration Lawyers | USA Immigration Specialists London - UK </title>
<meta name="description" content="Contact London, UK based an experienced immigration law attorney firm - Solutions in Law, Specializing in U.S. immigration, Visas, Green Cards & Citizenship. Call 44 020 3178 5419 today!">
<meta name="keywords" content="USA Immigration, USA Visas, USA Immigration Lawyers,USA Green Cards, Green Cards, USA Citizenship, USA Migration, Live and Work in the USA, Work in the USA, US Immigration, US Visas, USA Immigration Attorneys, USA Residence">

    <meta HTTP-EQUIV="Content-Language" CONTENT="EN">
    <meta name="distribution" CONTENT="Global">
    <meta name="revisit-after" CONTENT="20 days">
    <meta name="robots" CONTENT="index,follow">
    <meta name="Googlebot" CONTENT="index,follow">
    <meta http-equiv='imagetoolbar' content='no'>
    <meta name='Rating' content='General'>
    <meta name='MSSmartTagsPreventParsing' content='true'>
    <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
	
	<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-19198483-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>


<!-- CSS -->
<link rel="stylesheet" type="text/css" href="css/style.css" />
<script type="text/javascript">
    function changeClass(id, clas)
    {
        document.getElementById(id).className = clas;
    }
</script>

</head>

<body>
<div id="content">

    <div class="header">
        <div class="floatleftt10"><a href="index.htm"><img src="images/logo.jpg" alt="US green cards, H1B, L1, B1, B2, visas, US Immigration"></a></div>
        <div class="floatrightt50"><p><span class="head_lgrey">TEL:</span> <span class="head_dgrey">(+44) 020 7969 2977&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="head_lgrey">EMAIL:</span> <span class="head_dgrey">info@solutionsinlaw.co.uk</span></p>
        <div class="social"><a href="http://www.facebook.com/pages/Solutions-In-Law-Ltd/332398416821864" target="_blank" title="Like us on Facebook"><img src="images/facebook.jpg" /></a>&nbsp;<a href="https://twitter.com/NicoleEdwards26" target="_blank" title="Follow us on Twitter"><img src="images/twitter.jpg" /></a>&nbsp;<a href="http://uk.linkedin.com/pub/nicole-edwards/37/27a/58" title="Find us on Linked in" target="_blank"><img src="images/linkedin.jpg" /></a>&nbsp;&nbsp;</div></div>

        <div class="clear5"></div>
           <div class="bg_head_menu">
            <div class="home"><a href="index.htm" class="menu_links">Home</a></div>
            <div class="about"><a href="about_solutions_in_law.htm" class="menu_links">About Us</a></div>
			<div class="recruitement"><a href="international_clients.html" class="menu_links">International Clients</a></div>
			<div class="recruitement"><a href="recruitment.htm" class="menu_links">Recruitment</a></div>
            <div class="recruitement"><a href="testimonials.html" class="menu_links">TESTIMONIALS</a></div>
             <div class="recruitement"><a href="http://www.solutionsinlaw.co.uk/usvisa/usimmigrationlawyer/" class="menu_links">Latest News</a></div>
            <div class="contact"><a href="contact.htm" class="menu_links">Contact US</a></div>
			<div class="contact"><a href="http://www.solutionsinlaw.co.uk/german_index.htm" class="menu_links">German Version</a></div>
					

        </div>
    </div>
    <div class="clear20"></div>
    <div class="site_content">
        <div class="col_left">
            <div><img src="images/main_img.jpg" alt="USA Immigration Attorneys, Employment, Business, Family and Education USA Visas" /></div>
            <div class="clear10"></div>
            <div class="floatleft"><h1>Contact Us</h1></div>
            <div class="clear"></div>
            <div class="smalltext">
                <p class="head">Contact Address: </p>
                              <p><strong>Solutions In Law Ltd</strong><br>
                                43-45 Portman Square<br>
                                London W1H 6HN<br>
                                UK<br>
                                <br>

                    <b>Tel:</b>(+44) 020 7969 2977</p>
                              <p><span class="maintext"><strong>Email:</strong></span> <a href="mailto:info@solutionsinlaw.co.uk" class="maintextlink">info@solutionsinlaw.co.uk</a></p>
<div><?php
if(count($errors) != 0){
echo '<h3>Sorry, please address the following errors:-</h3>';
echo '<ul>';
foreach ($errors as $error) {
echo '<li>' . $error . '</li>';}echo '</ul>';
}
?>
<p class="contacttext">Telephone: 0800 014 6013
<a href="mailto:support@web-writer-articles.co.uk">Email</a>
or fill in the form below and I will get back to you as soon as possible:</p>
<form style="padding:15px;" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >

<p>First Name:<br/> <input type="text" size="30" name="first_name" value="<?php echo htmlspecialchars($_POST['first_name'],ENT_QUOTES); ?>" id="fname" /></p>
<p> Surname:<br/><input type="text" size="30" name="surname" value="<?php echo htmlspecialchars($_POST['surname'],ENT_QUOTES); ?>" id="sname" /></p>
<p>E mail:<br/><input type="text" size="40" name="email" value="<?php echo htmlspecialchars($_POST['email'],ENT_QUOTES); ?>" id="email" /></p>
<p>How Can I help you?<br/>
  <textarea rows="10" cols="40" name="text"> <?php echo htmlspecialchars($_POST['text'],ENT_QUOTES); ?> </textarea></p><br />
  <input type="submit" name="submit" value="Submit " />
</form></div>

Thank you for your time :slight_smile:

Change the name of the script in contact2.php

Usually the PHP parser isn’t executed for .html scripts.

You have an html extension instead of php, and the php interpreter isn’t setup to handle html files, so Apache never serves the html extension to PHP. Rename it to contact2.php and it should function as expected.

That worked but now I get the following error message:

Warning: array_map() [function.array-map]: The first argument, ‘mysqli_prep’, should be either NULL or a valid callback in /home/solutio/public_html/contact2.php on line 12

Fatal error: Call to undefined function mysqli_prep() in /home/solutio/public_html/contact2.php on line 13

What is happening here?

thanks,

mysqli_prep doesn’t seem to exist, verify you have it written somewhere and its accessible to your page.