Showing posts with label php browser gives 500 error code. Show all posts
Showing posts with label php browser gives 500 error code. Show all posts

browser gives 500 error code

Wednesday, November 4, 2015

I have written this php code to execute after a form is submitted. When the form is submitted the browser just gives an error code 500, server error. Not sure what I'm doing wrong here. I tried to add try-catch to find out what this error was but it doesn't help.



<?php
try {
$firstname = htmlspecialchars($_POST['firstname']);
$lastname = htmlspecialchars($_POST['lastname']);
$email = htmlspecialchars($_POST['email']);
$phone = htmlspecialchars($_POST['phone']);

#
$firstname = mysqli_real_escape_string($firstname);
$lastname = mysqli_real_escape_string($lastname);
$email = mysqli_real_escape_string($email);
$phone = mysqli_real_escape_string($phone);

$servername = "localhost";
$username = "airsofto_oliver";
$password = "magnetar1";
$dbname = "airsofto_YummyYummy";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn - > connect_error) {
die("Connection failed: ".$conn - > connect_error);
}

$sql = "INSERT INTO `airsofto_YummyYummy`.`Customers` (`CustomerID`, `FirstName`, `LastName`, `Email`, `Tel`, `AddressFirstLine`, `AddressSecondLine`, `Postcode`, `Timestamp`) VALUES (NULL, '$firstname', '$lastname', '$email', '$phone', '', '', '', CURRENT_TIMESTAMP);";

if ($conn - > query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: ".$sql.
"<br>".$conn - > error;
}

$conn - > close();
} catch (Exception $e) {
echo 'Caught exception: ', $e - > getMessage(), "\n";
}
?>


Thanks in advance for everyone's help.