zlajapn zlajapn - 6 months ago 35
MySQL Question

INSERTING datas into table doesn't work,why?

I would like to insert data into table sortiranje1 after I have done with my first $sql statement. For some reason, there are no inserted records into table sortiranje1. Also there are no errors.

$sql = "SELECT * FROM komentari WHERE IDteksta=$b and Tip='vest' and Dodaj='da'";
$result = mysqli_query($conn, $sql);
while($row = mysqli_fetch_assoc($result)) {
//echo "zbir lajkova je " . $zbir . " a indeks vesti je " . $b;

$upis = "INSERT INTO sortiranje1 (IDteksta)
VALUES ('$b')";

Also, like you can see I have echo that var $b, and it's ok, but I have no idea why it's not inserted into table! Here is my code for table:

$db_selected = mysqli_select_db($conn,'neprodaji');
$sql = "CREATE TABLE IF NOT EXISTS sortiranje1 (
IDteksta INT(9) NOT NULL,
Rezultat INT(9) NOT NULL)";


the problem you are facing because you are not executing your insert query, so write this line after insert query:-

mysqli_query($conn, $upis);

Note:- if you want to put some check (condition) based on this insert query then assign it to a variable like $result = mysqli_query($conn, $upis); and use that variable for check. it will be Boolean type.