Hi I am having some trouble with a small project. It's my first time using mySQL and PHP so I'm just trying to get connectivity for now. I have followed some tutorials and I cannot connect to the database, I am getting the "Sorry! Data Couldnt be inserted!" error from my php script at the bottom of index.html.
I also have a password on the database for the root user however even when i type this in the php file it still wont work.
Any help is much appreciated guys.
index.html:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"></link>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
</head>
<body>
<div class= "container" style = "width:500px">
<div ng-app="myapp" ng-controller="usercontroller">
<label>Email</label>
<input type ="text" name="email" ng-model="email" class="form-control"/>
<br />
<label>Password</label>
<input type ="text" name="password" ng-model="password" class="form-control"/>
<br />
<input type="submit" name="btnInsert" ng-click="insertData()" value="ADD"/>
</div>
</div>
<script>
var app = angular.module('myapp',[]);
app.controller('usercontroller', function($scope, $http){
$scope.insertData = function(){
$http.post(
"insert.php",{
'email':$scope.email,
'password':$scope.password
}).then(function(response){
alert("Data inserted Successfully! YIPEEEE!!!");
console.log("Data inserted Successfully");
},function(error){
alert("Sorry! Data Couldnt be inserted!");
console.error(error);
});
}
});
</script>
</body>
</html>
and my insert.php:
<?php
//insert.php
$data = json_decode(file_get_contents("php://input"));
$email = $data->email;
$password = $data->password;
mysql_connect("localhost","root","");
mysql_select_db("test");
mysql_query ("INSERT INTO 'test_user'('email', 'password') VALUES ('".$email."','".$password."')") or die(mysql_error());
echo $email. " " .$password;
/*
if(mysqli_query($connect, $query)){
echo "User inserted...";
}
else{
echo "User not inserted...";
}
*/
#mysqli_real_escape_string($connect,
#mysqli_real_escape_string($connect,
?>
</div>