So I'm a beginner with PHP, and currently, I'm studying MySQL right now, and I'm having trouble with this particular code.
$connection = mysqli_connect('localhost','root','','loginapp');
$username = $_POST['username'];
$password = $_POST['password'];
$query = "INSERT INTO users(username,password) VALUES ('$username','$password')";
$result = mysqli_query($connection,$query);
if ($result)
echo 1
else if(!$result)
echo 0;
*Basically it echoes 1 if the username and password have been transferred to the database successfully, and 0 when it doesn't.
If I remember correctly, you only use quotes ' '
for strings and when passing variables, you don't need to encase them with ' or ". So, I tried removing the quotes from the variables in VALUES($username,$password)
and it starts to echo 0 instead. Can anyone provide me an explanation as to why the variables have to be enclosed with ' or " inside the VALUES so I'd have a better understanding of how it works?