<?php
session_start();
require('45789417/ref4780.php');
if (!isset($_SESSION['userid'])) {
  echo "<script language='Javascript'> location.href='login.php';</script>";
    exit();
  };
  if ($_SESSION['type_user_live'] == "Paciente") {
    echo "<script type='text/javascript'>  
  window.location='paci_virtual/index.php';
  </script>";
    }
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8"> 
<title>Historia Clínica, Clínica Los Robles</title>
</head>
<body>
<?php 
$name = $_POST['name'];
$email = $_POST['email'];
$username = $_POST['username'];
/* $password = md5($_POST["password"]); */
$password = md5("7981".$_POST["password"]); 
$type_user = $_POST['type_user'];
$consulta_mysql= mysqli_query($con,"SELECT username FROM user WHERE username = '$username'");
       if ( $registro = mysqli_fetch_assoc($consulta_mysql) ){
       	echo "<script type='text/javascript'>
			    alert('Nombre de usuario existente');
			    window.location='user.php';
		</script>";
		exit();
       };
$query = mysqli_query($con,"INSERT INTO user (username, name, password, email, type_user) 
VALUES ('$username', '$name', '$password', '$email', '$type_user');");

echo "<script type='text/javascript'>  
window.location='user.php?newuser=1';
</script>"

?>

</body>
</html>