Duenna
Duenna

Reputation: 2376

Just getting nothing from my form submission page (PHP)

i'm pretty new to web development but I'm currently playing with an idea I have, and I wanted to make a page that allowed logged in users to report a problem and it get send to whatever e-mail was in the e-mail field for that user. The problem is, when I click the submit button I just get taken to a white page, and it doesn't appear that any of the php is working, however. I did an include_once on my page top and page bottom for my pages and they showed up, so It would seem the PHP is getting run, but I'm getting nothing back. Could someone have a look at this and suggest why it might not be working?

Thanks.

This is the page with my form on, and it would appear that everything is working on here.

<?php
include_once("php_includes/problem_form_email.php"); ?>

  <form action="problem_form_email.php" method="post" name="reportform" id="reportform">
    <div>Full Name: </div>
    <input id="fullname" type="text" maxlength="64">
    <div>Your Email address:</div>
    <input id="tenantemail" type="text" maxlength="88">
    <div>Your Phone number:</div>
    <input id="phonenumber" type="text" maxlength="64">
    <div>House Number or Name:</div>
    <input id="housenumber" type="text" maxlength="64">
    <div>First Line of address:</div>
    <input id="streetname" type="text" maxlength="64">
    <div>City:</div>
    <input id="city" type="text" maxlength="64">
    <div>Your Postcode:</div>
    <input id="postcode" type="text" maxlength="14">
    <div>Type of Problem:</div>
    <select id="typeofproblem">
    <option value="">TYPE OF PROBLEM</option>
<option value="Water">Water</option>
<option value="Decor">Decor(Paintwork, wallpaper etc.)</option>
<option value="Heating">Heating</option>
<option value="Windows">Windows</option>
<option value="Flooring">Flooring</option>
<option value="Kitchen">Kitchen</option>
<option value="Furniture">Furniture</option>
<option value="Roofing">Roofing</option>
    </select>
    <div>Describe your problem (Please be detailed):</div>
    <TEXTAREA style="resize:none; width:300px;" name="probdesc" ROWS=8 COLS=64 onfocus="emptyElement('status')"></textarea>
    <div>How urgent is this problem?:<br> Urgency is to help us filter the most in need cases, please don't abuse it.</div>
    <select id="urgency" onfocus="emptyElement('status')">
    <option value="">Choose an option</option>
<option value="Very Low">Very Low</option>
<option value="Low">Low</option>
<option value="Medium">Medium</option>
<option value="High">High</option>
<option value="Very High">Very High</option>
    </select>

    <div>
    </div>
    <br /><br />
    <input type='submit' value="Report Problem">
  </form>

All the variables should then go to my other page, which will send an e-mail the the user and then display some sort of success HTML. This is where I think i've done something wrong. Take a look...

I used a template form submission page and changed it, the template form can be found here. http://www.freecontactform.com/email_form.php

I would just like to clarify that the HTML part of this php page doesn't get shown at al

    // EDIT THE 2 LINES BELOW AS REQUIRED
include_once("php_includes/db_conx.php");
$sql = "SELECT email FROM users WHERE id='$log_id' AND username='$log_username'LIMIT 1";

$email_to = mysqli_query($db_conx, $sql); 
echo "$email_to";
 $email_subject = "MOUSE ACCOUNT - A Tenant has reported a problem";


    function died($error) {

        // your error code can go here

        echo "We are very sorry, but there were error(s) found with the form you submitted. ";

        echo "These errors appear below.<br /><br />";

        echo $error."<br /><br />";

        echo "Please go back and fix these errors.<br /><br />";

        die();

    }



    // validation expected data exists

    if(!isset($_POST['fullname']) ||

        !isset($_POST['tenantemail']) ||

        !isset($_POST['phonenumber']) ||

        !isset($_POST['housenumber']) ||

        !isset($_POST['streetname']) ||

        !isset($_POST['city']) ||

        !isset($_POST['postcode']) ||

        !isset($_POST['typeofproblem']) ||

        !isset($_POST['probdesc']) ||

        !isset($_POST['urgency'] )) {

        died('We are sorry, but there appears to be a problem with the form you submitted.');      

    }

$fullname = preg_replace('#[^a-z0-9."@; ]#i', '', $_POST['fullname']);
$tenantemail = mysqli_real_escape_string($db_conx, $_POST['tenantemail']);
$phonenumber = preg_replace('#[0-9 ]#i', '', $_POST['phonenumber']);
$housenumber = preg_replace('#[^a-z0-9 ]#i', '', $_POST['housenumber']);
$streetname = preg_replace('#[^a-z0-9 ]', '', $_POST['streetname']);
$city = preg_replace('#[^a-z ]', '', $_POST['city']);
$postcode = preg_replace('#[^a-z0-9 ]', '', $_POST['postcode']);
$typeofproblem = preg_replace('#[^a-z0-9 ]', '', $_POST['typeofproblem']);
$probdesc = preg_replace('#[^a-z0-9."@; ]', '', $_POST['probdesc']);
$urgency = preg_replace('#[^a-z0-9 ]#i', '', $_POST['urgency']);


    $error_message = "";

    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';

  if(!preg_match($email_exp,$tenantemail)) {

    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';

  }

    $string_exp = "/^[A-Za-z .'-]+$/";

  if(!preg_match($string_exp,$fullname)) {

    $error_message .= 'The First Name you entered does not appear to be valid.<br />';

  }

  if(!preg_match($string_exp,$phonenumber)) {

    $error_message .= 'The Last Name you entered does not appear to be valid.<br />';

  }

  if(strlen($probdesc) < 2) {

    $error_message .= 'The Comments you entered do not appear to be valid.<br />';

  }

  if(strlen($error_message) > 0) {

    died($error_message);

  }

    $email_message = "Form details below.\n\n";



    function clean_string($string) {

      $bad = array("content-type","bcc:","to:","cc:","href");

      return str_replace($bad,"",$string);

    }

$email_from = "[email protected]";
$email_message = '<!DOCTYPE html><html><head><meta charset="UTF-8"><title>Maintenance Request</title></head><body style="margin:0px; font-family:Tahoma, Geneva, sans-serif;"><div style="padding:10px; background:#333; font-size:24px; color:#CCC;"><a href="http://www.mouseaccount.com"><img src="http://www.mouseaccount.com/images/logo.png" width="36" height="30" alt="Mouse Account" style="border:none; float:left;"></a>A tenant reported a problem!</div><div style="padding:24px; font-size:17px;">Hello,<br /><br />A tenant has reported a problem at their property, please view below to see the details of the report so you can contact them.
<br /><br />Name: <b>'.$fullname.'</b><br /><br />
<br /><br />Tenants Contact Email: <b>'.$tenantemail.'</b><br /><br />
<br /><br />Tenants Phone Number: <b>'.$phonenumber.'</b><br /><br />
<br /><br />House Number: <b>'.$housenumber.'</b><br /><br />
<br /><br />Street Name: <b>'.$streetname.'</b><br /><br />
<br /><br />City: <b>'.$city.'</b><br /><br />
<br /><br />Postcode: <b>'.$postcode.'</b><br /><br />
<br /><br />Category of Problem: <b>'.$typeofproblem.'</b><br /><br />
<br /><br />Description of their problem <br /><br />:'.$probdesc.'<br /><br />
<br /><br />Urgency Indicated by tenant: <b>'.$urgency.'</b><br /><br />

Tenants Contact Email:<br />* E-mail Address: <b>'.$e.'</b></div></body></html>';
$headers = "From: $from\n";
        $headers .= "MIME-Version: 1.0\n";
        $headers .= "Content-type: text/html; charset=iso-8859-1\n";
mail($to, $subject, $message, $headers);
echo "signup_success";
exit();





// create email headers

$headers = 'From: '.$email_from."\r\n".

'Reply-To: '.$email_from."\r\n" .

'X-Mailer: PHP/' . phpversion();

@mail($email_to, $email_subject, $email_message, $headers); 

?>

<html>
<head>
  <meta charset="UTF-8">
  <title>Mouse Account</title>
  <link rel="icon" href="favicon.ico" type="image/x-icon">
  <link rel="stylesheet" href="style/style.css">
  <script src="root/js/main.js"></script>
</head>
<body>

<?php include_once("template_pageTop.php");?>
<div id="maincontent">

<div id="pageMiddle">&nbsp;
    <div id="img1"><img src="images/welcome_toMA.png" id="img1"></img></div></div></div>
<?php include_once("template_pageBottom.php");?>

</body>
</html>



<?php

}

?>

Upvotes: 0

Views: 153

Answers (3)

Duenna
Duenna

Reputation: 2376

OK, so I've got it to show up one thing, the problem was I wasn't including checkuserlogin.php in my problem_form_email.php and so my sql statement couldn't execute. But now I just keep getting them errors that show up below. and I have no way to make them stop, any additional help?

Upvotes: 0

Hamza
Hamza

Reputation: 1583

Add name parameters like Class said and also change

<input type='submit' value="Report Problem">

to

<input type="submit" value="Report Problem">

Also remove

include_once("php_includes/problem_form_email.php");

You dont need this, otherwise you are not closing php tag

<?php
include_once("php_includes/problem_form_email.php");

Change it to

<?php
include_once("php_includes/problem_form_email.php"); ?>

Upvotes: 0

Class
Class

Reputation: 3160

it looks like you have a lot inputs without any name parameters which PHP uses to populate $_GET/$_POST

<input id="fullname" type="text" maxlength="64">

which should look like:

<input id="fullname" name="fullname" type="text" maxlength="64">
                     ^^^^^^^^^^^^^^^

Theres might be more errors in your script but adding this should help you some

Also you mentioned that $log_id and $log_username are being populated but where ischeckuserlogin.php being called? is it being called in db_conx.php otherwise theres your problem. You might want to turn on error messages to receive messages.

Upvotes: 1

Related Questions