Contact form not working properly


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:

The code is as follows:

<?php require_once("connect/connection.php");
$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";
$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";
mail($email2, $subject2, $message2);
header('Location: brief_return.php');
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">


<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']);

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


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


<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"></span></p>
        <div class="social"><a href="" target="_blank" title="Like us on Facebook"><img src="images/facebook.jpg" /></a>&nbsp;<a href="" target="_blank" title="Follow us on Twitter"><img src="images/twitter.jpg" /></a>&nbsp;<a href="" 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="" 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="" class="menu_links">German Version</a></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>

                    <b>Tel:</b>(+44) 020 7969 2977</p>
                              <p><span class="maintext"><strong>Email:</strong></span> <a href="" class="maintextlink"></a></p>
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="">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 " />

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?


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