This is the registration form, I want its data to be stored in MySQL database
It prints else part always i.e. failed to submit
My Php file below: I made a simple registration form. I want its data to be stored in database I mentioned in $db variable. I already created database in phpmyadmin which I mentioned in the file. But I don't know why this code is not working. Please tell me what line of code is wrong and how should I correct it.
<?php
$host="localhost";
$user="root";
$pwd="";
$db="mohita";
$conn=mysqli_connect($host,$user,$pwd,$db) or die("unable to connect");
?>
<html>
<head>
<title>Try here</title>
</head>
<body>
<form method="post">
<input type="text" name="yourname"/>
<input type="email" name="mailid"/>
<input type="password" name="mypass"/>
<input type="number" name="phn"/>
<textarea rows="5" cols="20" name="address"/></textarea>
<input type="submit" name="reg"/>
</form>
</body>
</html>
<?php
if(isset($_POST['reg'])){
$yourname=$_POST['yourname'];
$mailid=$_POST['mailid'];
$mypass=$_POST['mypass'];
$phn=$_POST['phn'];
$address=$_POST['address'];
$query="insert into login(Name,Email,Pass,Mobile,Address) values('$yourname','$mailid','$mypass','$phn','$address')";
$run=mysqli_query($conn,$query);
if($run){
echo "<h1>Data submitted successfully</h1>";
}
else{
echo "<h1>Failed to submit data</h1>";
}
}
?>