<?php
require("Conn.php");
require("MySQLDao.php");

$servername = "db.soic.indiana.edu";
$serverusername = "caps15_team3";
$serverpassword = "my+sql=caps15_team3";
$dbname = "caps15_team3";

$conn = new mysqli($servername, $serverusername, $serverpassword, $dbname);

if ($conn->connect_error) {
  die ("Connection failed: " . $conn->connect_eccor);
} else {
  echo "Connected.";
}


$username = htmlentities($_POST["username"]);
$fname = htmlentities($_POST["fname"]);
$lname = htmlentities($_POST["lname"]);
$email = htmlentities($_POST["email"]);
$password = htmlentities($_POST["password"]);

if(empty($email) || empty($password) || empty($username) || empty($fname) || empty($lname))
{
$returnValue["status"] = "error";
$returnValue["message"] = "Missing required field";
echo json_encode($returnValue);
return;
}

$sql = "UPDATE user SET user_name='" .$username. "',user_fname='" .$fname. "', user_lname='" .$lname. "', user_password='" .$password. "' WHERE user_email='" .$email. "'";

//$result = $conn->query($sql);

$result = mysqli_query($conn,$sql);

if ($result) {
  echo "Record posibly changed.";
} else {
  echo "Error updating record: " . mysqli_error($conn);
}

mysqli_close($conn);
?>