Page 1 of 2

Warning: mysqli::__construct(): (HY000/1045): Access denied for user 'root'@'localhost' (using passw

Posted: Tue Jul 14, 2020 6:22 pm
by sabrina
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();
?>

Re: i keep gets this error,can you help me please.

Posted: Tue Jul 14, 2020 10:11 pm
by shah.nawaraj.forum
Are you able to visit phpMyadmin page?

Re: i keep gets this error,can you help me please.

Posted: Wed Jul 15, 2020 2:15 pm
by sabrina
yes, I can

Re: i keep gets this error,can you help me please.

Posted: Wed Jul 15, 2020 2:17 pm
by sabrina
it is something wrong with my DB or my coding??

Re: i keep gets this error,can you help me please.

Posted: Wed Jul 15, 2020 3:14 pm
by shah.nawaraj.forum
Did you change your mysql port number?

Re: i keep gets this error,can you help me please.

Posted: Wed Jul 15, 2020 11:46 pm
by sabrina
yes, I change it into 3308 because if not my wamp server not turning into green

Re: i keep gets this error,can you help me please.

Posted: Thu Jul 16, 2020 7:09 am
by shah.nawaraj.forum
sabrina wrote: Wed Jul 15, 2020 11:46 pm yes, I change it into 3308 because if not my wamp server not turning into green
Ok then in 2nd line, you have to write your new port number along with localhost. Example :
Code: Select all
$servername = "localhost:3308";

Re: i keep gets this error,can you help me please.

Posted: Thu Jul 16, 2020 5:35 pm
by sabrina
Tq so much for helping me..

Re: i keep gets this error,can you help me please.

Posted: Thu Jul 16, 2020 6:43 pm
by shah.nawaraj.forum
sabrina wrote: Thu Jul 16, 2020 5:35 pm Tq so much for helping me..
I glad that it help.

Re: i keep gets this error,can you help me please.

Posted: Fri Jul 17, 2020 7:51 am
by sabrina
sorry, can I ask one last question? why this error occurs?

Fatal error: Uncaught Error: Call to undefined function mysql_error() in C:\wamp64\www\clinic\afterupdate.php on line 34

echo "Query Failed: " . mysql_error(); <- this is line 34