Reputation: 49
I have a html document with a form page that is debugged and is correct. The problem is the DB, Im hosted on strato, but I think its more of a code problem rather than a serverside problem. The html document is a form that feeds in the Super globals POST, so First, Lastname, Email, Subject, Address, PLZ and message. However the message is not going into the db, its gonna get mailed to my support email. I havent setupp the mail function because I wanted to debug the sql db part first. All the if statements filter the input, for valid email and patterns, so you are not allowed to put in numbers in the form of the html form. I know you can make the pattern in html but I want 100% safety. After the inputs have passed all the filters the connection to my db is going to connect, I want to insert first, lastname and email address and subject as well as plz.
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL);
$subject = $_POST['thema'];
$address = $_POST['address'];
$plz = $_POST['plz'];
$text = $_POST['text'];
$pattern = "/^([a-zA-Z' äöü ÄÖÜ]+)$/";
$pattern_plz = "/[0-9]$/";
//VALID INPUT//
if(preg_match($pattern, $fname)){
if(preg_match($pattern, $lname)){
if($email == TRUE){
if(preg_match($pattern_plz, $plz)){
if(is_numeric($plz)){
$con = new mysqli($host, $db, $user, $passwd) or die ("Keine Verbindung konnte aufgebaut werden");
if($con){
$sql="INSERT INTO contact (fname, lname, email, thema, address, plz)
VALUES ($fname, $lname, $email, $subject, $address, $plz)";
if($con->mysqli_query($sql) == TRUE){
echo "success";
}else{mysqli_close($con); exit("Keine Verbindung konnte aufgebaut werden");}
}else{mysqli_close($con); exit("Keine Verbindung konnte aufgebaut werden");}
}else{exit("Inavlid PLZ");}
}else{exit("Inavlid PLZ");}
}else{exit("Inavlid email");}
}else{exit("Inavlid email");}
}else{exit("Inavlid lastname");}
Upvotes: 0
Views: 67
Reputation: 105
as you are using it on live hosting, displaying error might be turned off from your directadmin or cpanel, you can find php options in hosting and turn on, or else you can use try catch for example
//trigger exception in a "try" block
try {
//Your code
}
//catch exception
catch(Exception $e) {
echo 'Message: ' .$e->getMessage(); // display error
}
Upvotes: 1