这是注册表,我希望其数据存储在MySQL数据库中
它总是打印其他部分,即提交失败
我的Php文件如下:我做了一个简单的注册表。我希望将其数据存储在$ db变量中提到的数据库中。我已经在文件中提到的phpmyadmin中创建了数据库。但是我不知道为什么这段代码不起作用。 请告诉我哪一行代码是错误的,我应该如何纠正。
<?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>";
}
}
?>
答案 0 :(得分:-2)
尝试一下,让我知道是否可行!
<html>
<head>
<title>Try here</title>
</head>
<body>
<form method="post" action="">
<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>
<?php
if(isset($_POST['reg'])){
$host="localhost";
$user="root";
$pwd="";
$db="mohita";
$yourname=$_POST['yourname'];
$mailid=$_POST['mailid'];
$mypass=$_POST['mypass'];
$phn=$_POST['phn'];
$address=$_POST['address'];
$conn=mysqli_connect($host,$user,$pwd,$db) or die("unable to connect");
$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>";
}
}
?>
</body>
</html>