数据未添加到php my admin上的数据库中
我正在使用wamp服务器。我正在尝试存储用户在我的表单中填写的数据。但我不知道为什么它没有被添加。 这些是我的php文件:(所有文件都是用记事本++编写的) init.php:数据未添加到php my admin上的数据库中,php,database,phpmyadmin,localhost,wampserver,Php,Database,Phpmyadmin,Localhost,Wampserver,我正在使用wamp服务器。我正在尝试存储用户在我的表单中填写的数据。但我不知道为什么它没有被添加。 这些是我的php文件:(所有文件都是用记事本++编写的) init.php: <?php $host = "localhost"; $db_user = "harsh"; $db_password = "password"; $db_name = "user_db"; $con = mysqli_connect($host,$db_user,$db_password,$db_name);
<?php
$host = "localhost";
$db_user = "harsh";
$db_password = "password";
$db_name = "user_db";
$con = mysqli_connect($host,$db_user,$db_password,$db_name);
?>
<?php
require "init.php";
$name = $_POST["name"];
$adharnumber = $_POST["adharnumber"];
$email = $_POST["email"];
$password = $_POST["password"];
$contact = $_POST["contact"];
$sql="select * from individualuser_info where email like '".$email."';";
$result = mysqli_query($con,$sql);
$response = array();
if(mysqli_num_rows($result)>0)
{
$code = "reg_failed";
$message = "User already exist....";
array_push($response,array("code"=>$code,"message"=>$message));
echo json_encode($response);
}
else
{
$sql = "insert into individualuser_info (`".$name."','".$adharnumber."','".$email."','".$password."','".$contact."');";
$result = mysqli_query($con,$sql);
$code = "reg_success";
$message = "thank you .now you can login....";
array_push($response,array("code"=>$code,"message"=>$message));
echo json_encode($response);
}
mysqli_close($con);
?>
<html>
<body>
<form action ="register1.php", method="post">
<table>
<tr>
<td>Name : </td><td><input type="text" name="name"/></td>
</tr>
<tr>
<td>Adhar number : </td><td><input type="text" name="adharnumber"/></td>
</tr>
<tr>
<td>Email:</td><td><input type="text" name="email"/></td>
</tr>
<tr>
<td>Password:</td><td><input type="password" name="password"/></td>
</tr>
<tr>
<td>Contact:</td><td><input type="text" name="contact"/></td>
</tr>
<tr>
<td><input type = "submit" value="Register"/></td>
</tr>
</table>
</form>
</body>
</html>
register1.php:
<?php
$host = "localhost";
$db_user = "harsh";
$db_password = "password";
$db_name = "user_db";
$con = mysqli_connect($host,$db_user,$db_password,$db_name);
?>
<?php
require "init.php";
$name = $_POST["name"];
$adharnumber = $_POST["adharnumber"];
$email = $_POST["email"];
$password = $_POST["password"];
$contact = $_POST["contact"];
$sql="select * from individualuser_info where email like '".$email."';";
$result = mysqli_query($con,$sql);
$response = array();
if(mysqli_num_rows($result)>0)
{
$code = "reg_failed";
$message = "User already exist....";
array_push($response,array("code"=>$code,"message"=>$message));
echo json_encode($response);
}
else
{
$sql = "insert into individualuser_info (`".$name."','".$adharnumber."','".$email."','".$password."','".$contact."');";
$result = mysqli_query($con,$sql);
$code = "reg_success";
$message = "thank you .now you can login....";
array_push($response,array("code"=>$code,"message"=>$message));
echo json_encode($response);
}
mysqli_close($con);
?>
<html>
<body>
<form action ="register1.php", method="post">
<table>
<tr>
<td>Name : </td><td><input type="text" name="name"/></td>
</tr>
<tr>
<td>Adhar number : </td><td><input type="text" name="adharnumber"/></td>
</tr>
<tr>
<td>Email:</td><td><input type="text" name="email"/></td>
</tr>
<tr>
<td>Password:</td><td><input type="password" name="password"/></td>
</tr>
<tr>
<td>Contact:</td><td><input type="text" name="contact"/></td>
</tr>
<tr>
<td><input type = "submit" value="Register"/></td>
</tr>
</table>
</form>
</body>
</html>
显示一条成功消息,但从未实际检查操作是否成功。查看mysqli\u错误
。您的代码对SQL注入非常开放,很有可能出现语法错误。您的问题可能是(在您的插入中。但正如David所说,请保护自己不受sql注入的影响!如所述。了解for。甚至是不安全的。此外,如果您查看错误日志,他们应该会发现这一点-在没有错误的情况下进行开发设置以显示所有内容是不明智的。