无法使用PHP

时间:2017-06-22 18:04:12

标签: php mysql

我正在学习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);




?>

1 个答案:

答案 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

这里的代码可以帮到你。 :)