我正在学习MySQL课程,我正在学习如何在用户输入代码(电子邮件和密码)中将脚本中的信息放入phpMyAdmin的数据库中。我似乎无法让它发挥作用?当我通过错误检查程序时,我的代码没有任何错误。我也是PHP和MySQL的新手。我知道它可以找到数据库,因为我可以更新现有数据。
<?php
$link = mysqli_connect("host", "username", "password", "username");
if (mysqli_connect_error()) {
die ("There was an error connecting to the database");
}
$query = "INSERT INTO `users` (`email`, `password`) VALUES('email', 'password')";
mysqli_query($link, $query);
$query = "SELECT * FROM users";
if ($result = mysqli_query($link, $query)) {
$row = mysqli_fetch_array($result);
echo "Your email is ".$row[1]." and your password is ".$row[2];
}
?>
答案 0 :(得分:0)
创建了精致版本。核实。
<?php
$link = mysqli_connect("host", "username", "password", "username");
if (mysqli_connect_error()) {
die ("There was an error connecting to the database");
}
$query = "INSERT INTO `users` (`email`, `password`) VALUES('email', 'password')";
$result = mysqli_query($link, $query);
if($result != false)
{
echo "The record has been successfully inserted.<br>";
}
else
{
echo "Error Occured in the INSERT query.<br>Error : ".mysqli_error($link);
}
$query = "SELECT * FROM users";
$result = mysqli_query($link, $query);
if($result != false)
{
echo mysqli_num_rows($result)." Records found.<br>";
while($rows = mysqli_fetch_array($result))
{
echo $rows["email"]."<br>";
}
}
else
{
echo "Error Occured in the SELECT query.<br>Error : ".mysqli_error($link);
}
mysqli_close($link);
?>
答案 1 :(得分:0)
<强>更新强>
事实证明我没有设置auto_increment设置,因此我设置数据库的方式不正确!他在我正在经历的教程中设置了另一个数据库,我发现他正在做的事情。感谢大家帮助我解决问题的努力!
答案 2 :(得分:-3)
为什么你不尝试用php接收它们?
简单地制作
$email= $POST['email']
$password= $POST['password']
将查询更改为
$query = "INSERT INTO `users` (`email`, `password`) VALUES(" .$email. ", ". $password.")";