I can't connect from the database on the VS code live server from PHPMyAdmin Mysql localhost. In the localhost, I am able to connect to the database, and everything's working fine but while running the live website its shows can't connect to the database. Here's the code:-
<?php
session_start();
$name = "";
$email = "";
$password = "";
$errors = array();
if(isset($_POST["btn"]))
{
$name=$_POST["name"];
$email=$_POST["email"];
$password=$_POST["password"];
$db = mysqli_connect('localhost','root','','innvocon') or die("Can't connect to Database");
if(empty($name))
{
array_push($errors, "Name is required.");
}
if(empty($email))
{
array_push($errors, "Email is required.");
}
if(empty($password))
{
array_push($errors, "Password is required.");
}
$check = "SELECT * FROM user WHERE email = '$email' LIMIT 1";
$results = mysqli_query($db ,$check);
$users = mysqli_fetch_assoc($results);
if($users)
{
if($users['email'] === $email){array_push($errors, "This Email ID already exists");
}
}
if(count($errors) == 0 )
{
$password = md5($password);
$query = "INSERT INTO user(name , email , password) VALUES('$name', '$email' , '$password')";
$res=mysqli_query($db, $query);
}
}
?>
Aucun commentaire:
Enregistrer un commentaire