I have made a signup form in HTML and PHP.
The HTML form successfully calls the PHP script.
But when ever the form is submitted, the PHP code is displayed on the screen.
My PHP script is-
$secretKey = '';
$statusMsg = '';
if(isset($_POST['submit'])){
if(!empty($_POST['name']) && !empty($_POST['email'])){
if(!empty($_POST['h-captcha-response'])){
$verifyURL = 'https://hcaptcha.com/siteverify';
$token = $_POST['h-captcha-response'];
$data = array(
'secret' => $secretKey,
'response' => $token,
'remoteip' => $_SERVER['']
);
$curlConfig = array(
CURLOPT_URL => $verifyURL,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $data
);
);
$ch = curl_init();
curl_setopt_array($ch, $curlConfig);
$response = curl_exec($ch);
curl_close($ch);
$responseData = json_decode($response);
if($responseData->success){
$name = !empty($_POST['username'])?$_POST['username']:'';
$email = !empty($_POST['email'])?$_POST['email']:'';
$errors = array();
$db = mysqli_connect('localhost', 'root', '', '');
$username = mysqli_real_escape_string($db, $_POST['username']);
$email = mysqli_real_escape_string($db, $_POST['email']);
$user_check_query = "SELECT * FROM userWHERE username='$username' OR email='$email' LIMIT 1";
$result = mysqli_query($db, $user_check_query);
$user = mysqli_fetch_assoc($result);
if ($user) { // if user exists
if ($user['username'] === $username) {
array_push($errors, "Username already exists");
}
$statusMsg = 'Your contact request has submitted successfully.';
}else{
$statusMsg = 'Robot verification failed, please try again.';
}
}else{
$statusMsg = 'Please check on the CAPTCHA box.';
}
}else{
$statusMsg = 'Please fill all the mandatory fields.';
}
}
echo $statusMsg;
?>
So the output is all the above without indentations.
Why is this happening?
PHP 7.2 on Apache2.
Aucun commentaire:
Enregistrer un commentaire