简体   繁体   中英

Cannot insert data into mySQL database using PHP

I'm learning PHP and having a hard time inserting data into my mySQL database using PHP. PHP is working and the connection appears fine. Thanks for the help, here's my code:

<?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);




?>
<?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);    
?>

add your id to autoincrement in database and also give primary key

Here code which can helps you. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM