I need to send the name
, lastname
, number
and email
to a database. I created this code:
<?php
echo $name;echo "<br>";
echo $lastname;echo "<br>";
echo $email;echo "<br>";
echo $celnumber;echo "<br>";
$servername = "localhost";
$username = "usertest1";
$password = "1234";
$dbname="usertest1";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// prepare sql and bind parameters
$stmt = $conn->prepare("INSERT INTO tabela_script (name, lastname, email, celnumber)
VALUES (:name, :lastname, :email, :celnumber)");
$stmt->bindParam(':firstname', $name);
$stmt->bindParam(':lastname', $lastname);
$stmt->bindParam(':email', $email);
$stmt->bindParam(':celnumber', $celnumber);
$stmt->execute();
echo "New record created successfully";
}
catch(PDOException $e)
{
echo "Error: " . $e->getMessage();
echo "<br>";
echo "<a href=\"main_html.html\"><h1>TRY AGAIN</h1></a>";
}
$conn = null;?>
And getting the error below:
Error: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined