Getting Contact form to work with SQL database
When I run my contact form, it redirects to the form-handler.php, but gives me a blank page and nothiing has been inserted to the database.
Contact.html:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Contact UMMA</title>
<link href="styles.css" rel="stylesheet" type="text/css">
</head>
<body><!--
Replace form-handler.php with URL where to send the form-data when the form is submitted
Goto http://w3c.github.io/html-reference/input.text.html#input.text for more information on all attributes that can be used with text input field
-->
<center><img src="UMMA Logo 2.png" width="200" height="186" alt=""/></center>
<div class="box">
<h1><center>Contact UMMA!</center>
</h1>
<center>
<form method="post" action="form-handler.php" name="ContactUs" id="ContactUs">
<div>
<label for="Country" ><strong>Country:</strong> </label><span class="required">*</span>
<label for="Country">United States </label>
<input type="radio" name="Country" id="US" tabindex="1" value="1" checked>
<label for="NotUS">Other</label>
<input type="radio" name="Country" id="NotUS" tabindex="2" value="NULL">
</div>
<div>
<label for="Last"><strong>Last Name:</strong> <span class="required">*</span> </label>
<input type="text" id="LName" name="LName" value="" placeholder="Your last name" required="required" autofocus />
</div>
<div>
<label for="First"><strong>First Name: </strong><span class="required">*</span> </label>
<input type="text" id="FName" name="FName" value="" placeholder="Your first name" tabindex="3" required="required" autofocus />
</div>
<div>
<label for="Orgn"><strong>Organization:</strong> <span class="required">*</span> </label>
<input type="text" id="Org" name="Org" value="" placeholder="Your School or Organization" tabindex="4" required="required" autofocus />
</div>
<div>
<label for="email"><strong>Email Address:</strong> <span class="required">*</span> </label>
<input type="email" id="email" name="email" value="" placeholder="youraddress@email.com" tabindex="5" required="required" />
</div>
<div>
<label for="Phone"><strong>Preferred Phone No. </strong><span class="required">* </span> </label>
<input type="Phone" id="Phone" name="Phone" value="" placeholder="Phone #" required="required" /><br>
(Numbers only, Country code if outside USA)
</div>
<div>
<label for="subject"><strong>Subject:</strong> </label>
<select id="subject" name="subject" tabindex="4">
<option value="General ">General Inquiry</option>
<option value="Join">Joining UMMA</option>
<option value="Compliment">A compliment for UMMA</option>
<option value="Concern">I have a concern</option>
</select>
</div>
<div>
<label for="message"><strong>Message:</strong> <span class="required">*</span> </label>
<textarea id="message" name="message" rows="7" cols="50" placeholder="Write your message here." required tabindex="5" maxlength="255"></textarea>
</div>
<div>
<h4>Would you like us to respond?</h4>
<label for="radio-choice-1">Yes</label>
<input type="radio" name="radio-choice" id="radio-choice-1" tabindex="6" value="1" checked>
<label for="radio-choice-2">No</label>
<input type="radio" name="radio-choice" id="radio-choice-2" tabindex="7" value="NULL">
</div>
<div>
<input type="submit" value="Submit" id="submit" />
<br><br>
</div>
</form>
</center>
</div>
</body>
</html>
form-handler.php:
<?php
//creating connection to database
$con=mysqli_connect("[removed by moderator]","[removed by moderator]","","[removed by moderator]") or die(mysqli_error());
//check whether submit button is pressed or not
if((isset($_POST['submit'])))
{
//fetching and storing the form data in variables
$Country = $con ->real_escape_string($_POST['country']);
$UFName = $con ->real_escape_string($_POST['FName']);
$ULName = $con->real_escape_string($_POST['LName']);
$UGuestID = $con->real_escape_string($_POST['Email']);
$Phone = $con->real_escape_string($_POST['Phone']);
$Org = $con->real_escape_string($_POST['Orgn']);
$USubject = $con->real_escape_string($_POST['subject']);
$UMessage = $con->real_escape_string($_POST['message']);
$UReply = $con->real_escape_string($_POST['radio-choice']);
//query to insert the variable data into the database
$sql="INSERT INTO 'guests' ('id','UGuestid','Country','Phone', 'ULName', 'UFName', 'Org', 'USubject', 'UMessage', 'UReplyReq') VALUES (NULL,'.$UGuestID','.$Country','.$Phone','.$ULName','.$UFName','.$Org','.$USubject','.$UMessage','UReply')";
//Execute the query and returning a message
if(!$result = $con->query($sql)){
die('Error occured [' . $conn->error . ']');
}
else
echo "Thank you! We will get in touch with you soon";
}
?>
How do I get the form handler to perform the sql query?
[Sensitive log-in data removed by moderator for your protection.]
