我正在学习PHP并且很难使用PHP将数据插入mySQL数据库。 PHP工作正常,连接正常。感谢您的帮助,这是我的代码:
<?php
$conn = mysqli_connect("localhost","root","admin","USER_DATA");
if(!$conn)
{
echo "Error connecting to DB";
echo "Debug errno: " . mysqli_connect_errno() . PHP_EOL;
exit;
}
else
{
echo "Connected successfully!";
}
$sql = "INSERT INTO `login` (`id`, `username`, `password`) VALUES (NULL, 'rrrrrdfbdfgv', $
$result->query($sql);
?>
答案 0 :(得分:0)
<?php
$conn = mysqli_connect("localhost","root","admin","USER_DATA");
if(!$conn)
{
echo "Error connecting to DB";
echo "Debug errno: " . mysqli_connect_errno() . PHP_EOL;
exit;
}
else
{
echo "Connected successfully!";
}
$sql = "INSERT INTO `login` (`username`, `password`) VALUES ('rrrrrdfbdfgv', $password)";
mysqli_query($conn,$sql);
?>
将您的id
添加到数据库中的autoincrement
并同时提供primary key
这里的代码可以帮到你。 :)