Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement in /mnt/web411/c2/96/59561596/htdocs/boazvlogs/maintenance/process.php on line 34 Hello Marc Molenaar!, your message has been saved!
- <?php
- if ($_SERVER["REQUEST_METHOD"] == "POST") {//Check it is comming from a form
- error_reporting(E_ALL);
- ini_set('display_errors', 'On');
- //mysql credentials
- $mysql_host = "example.com";
- $mysql_username = "example";
- $mysql_password = "example";
- $mysql_database = "example";
- $name = filter_var($_POST["name"], FILTER_SANITIZE_STRING); //set PHP variables like this so we can use them anywhere in code below
- $email = filter_var($_POST["email"], FILTER_SANITIZE_EMAIL);
- if (empty($name)){
- die("Please enter your name");
- }
- if (empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)){
- die("Please enter valid email address");
- }
- //Open a new connection to the MySQL server
- //see https://www.sanwebe.com/2013/03/basic-php-mysqli-usage for more info
- $mysqli = new mysqli($mysql_host, $mysql_username, $mysql_password, $mysql_database);
- //Output any connection error
- if ($mysqli->connect_error) {
- die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
- }
- $statement = $mysqli->prepare("INSERT INTO form (name, email) VALUES(name, email)"); //prepare sql insert query
- //bind parameters for markers, where (s = string, i = integer, d = double, b = blob)
- $statement->bind_param("sss", $name, $email); //bind values and execute insert query
- if($statement->execute()){
- print "Hello " . $name . "!, your message has been saved!";
- }else{
- print $mysqli->error; //show mysql error if any
- }
- }
- ?>
Add Comment
Please, Sign In to add comment