Reputation: 1
I am new here and read other questions but couldn't find answer. I am trying to write a simple PHP script to insert new row into MySQL database.
I am using Ubuntu Server without GUI. My script looks like that.
<?php
$host = "localhost";
$db_user = "root";
$db_password = "";
$db_name = "books_test";
$polaczenie = mysqli_connect($host, $db_user, $db_password, $db_name);
if($polaczenie->connect_errno!=0)
{
echo "Error\n";
}
else
{
echo "Polaczono z baza\n";
$SQL="INSERT INTO books VALUES (DEFAULT, 'Alicja w Krainie czarów', 'Carol Luis',
'England')";
if (@mysqli_query($SQL, $polaczenie)){
echo "Nowy rekord dodany prawidlowo\n";
}
else{
echo "Nie dodano nowego rekordu\n";
}
} ?>
It shows that the connection with database is OK but still it doesn't insert a row. Do you have any ideas?
Thanks a lot
Upvotes: 0
Views: 1308
Reputation: 3795
Just change mysqli_query($SQL, $polaczenie)
to mysqli_query($polaczenie,$SQL)
But try to use the object style only not the procedual style!! And dont mix them, read here: http://php.net/manual/en/mysqli.quickstart.dual-interface.php
Upvotes: 1