mysql - Php Post Insert Error Access denied for user 'root'@'localhost' (using password: YES) -


i'm posting data using php mysqlserver. (rest service) problem i'm getting error:

connection failed: access denied user 'root'@'localhost' (using password: yes).

i changed query insert select statement , works, retrieve data cant seem insert. have checked privileges , changed password. i'm sure question has been asked before solutions have tried don't work problem unique context. i'm not sure if code or what? please help.

<?php  $servername = "localhost"; $username = "root"; $password = "****"; $dbname = "tripbuddy";  $name = $_post['name']; $surname = $_post['surname']; $email = $_post['email']; $password = $_post['password'];  // create connection  $conn = new mysqli($servername, $username, $password, $dbname); // check connection  if ($conn->connect_error) {  die("connection failed: " . $conn->connect_error);  }    $sql = "insert 'tripbuddy'.'appuser01' ('name', 'surname', 'email',              'password') values ('$name','$surname','$email','$password');";   if ($conn->query($sql) === true) {   echo "new record created successfully";   } else {    echo "error: " . $sql . "<br>" . $conn->error;   }    $conn->close();   ?> 

what happening here you're using $password both db , post array.

  • you need change 1 of them conflict. have seen happen before.

then query using regular quotes instead of ticks.

$sql = "insert `tripbuddy`.`appuser01` (`name`, `surname`, `email`, `password`)           values ('$name','$surname','$email','$password');"; 

your present code open sql injection. use mysqli_* prepared statements, or pdo prepared statements.

edit:

as saty stated; use mysqli_affected_rows() truthness.


passwords

i noticed may storing passwords in plain text. not recommended.

use 1 of following:

other links:


add error reporting top of file(s) find errors.

<?php  error_reporting(e_all); ini_set('display_errors', 1);  // rest of code 

sidenote: displaying errors should done in staging, , never production.

  • making sure form use post method , inputs bear matching name attributes.

i.e.: name="name" post array $_post['name'] etc.

  • note name , name 2 different animals , case-sensitive.

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -