- Tue Jul 14, 2020 6:22 pm
#57
Warning: mysqli::__construct(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: NO) in C:\wamp64\www\clinic\insert.php on line 8
This is my coding.
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "clinic";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("connection failed: " . $conn->connect_error);
}
$patient_id = $_POST['txt_patientid'];
$patient_name = $_POST['txt_patientname'];
$address = $_POST['txt_address'];
$treatment= $_POST['txt_treatment'];
$email = $_POST['txt_email'];
$telephone_no = $_POST['txt_telephoneno'];
$sql = "INSERT INTO tbl_registration (patient_id, patient_name, address, treatment, email, telephone_no) VALUES('$patient_id', '$patient_name','$address', '$treatment', '$email', '$telephone')";
if ($conn->query($sql) === TRUE) {
$last_id = $conn->insert_id;
echo "New record created successfully. Last inserted ID is: " . $last_id;
} else
{
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
This is my coding.
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "clinic";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("connection failed: " . $conn->connect_error);
}
$patient_id = $_POST['txt_patientid'];
$patient_name = $_POST['txt_patientname'];
$address = $_POST['txt_address'];
$treatment= $_POST['txt_treatment'];
$email = $_POST['txt_email'];
$telephone_no = $_POST['txt_telephoneno'];
$sql = "INSERT INTO tbl_registration (patient_id, patient_name, address, treatment, email, telephone_no) VALUES('$patient_id', '$patient_name','$address', '$treatment', '$email', '$telephone')";
if ($conn->query($sql) === TRUE) {
$last_id = $conn->insert_id;
echo "New record created successfully. Last inserted ID is: " . $last_id;
} else
{
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>