I'm trying to put my database online put in my code i have PHP
files that are only PHP
and others PDO
.
I added 2 different connections to each :
database.php(PDO)
$user='';
$pass='';
$db='';
$dbserver='';
try {
$conn = new PDO("mysql:host=$dbserver;dbname=$db", $user, $pass);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
?>
One of the PDO files I started with :
<?php
header('Access-Control-Allow-Origin: *');
include('database.php');
try {
$conn = new PDO("mysql:host=$dbserver;dbname=$db", $user, $pass);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
$data = array();
$a_username = filter_var($_POST['a_username'], FILTER_SANITIZE_STRING, FILTER_FLAG_ENCODE_LOW);
$p_username = filter_var($_POST['p_username'], FILTER_SANITIZE_STRING, FILTER_FLAG_ENCODE_LOW);
$password = filter_var($_POST['password'], FILTER_SANITIZE_STRING, FILTER_FLAG_ENCODE_LOW);
$vpassword = filter_var($_POST['vpassword'], FILTER_SANITIZE_STRING, FILTER_FLAG_ENCODE_LOW);
try{
$sql = "INSERT INTO account_info (a_username,p_username, password, vpassword)
VALUES(:a_username, :p_username, :password, :vpassword)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':a_username', $a_username, PDO::PARAM_STR);
$stmt->bindParam(':p_username', $p_username, PDO::PARAM_STR);
$stmt->bindParam(':password', $password, PDO::PARAM_STR);
$stmt->bindParam(':vpassword', $vpassword, PDO::PARAM_STR);
$stmt->execute();
echo json_encode(array('message' => 'Congratulations the record was added to the database'));
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
No more errors but I still can't log in from my phone