Help resolving SQL error

Hi guys. I’m new here,I thought I can have an answer even so I think it could be pretty easy to slove the problem I’m stuck in it in th last two days.

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘* FROM roombook WHERE cout = ‘2020-03-03’’ at line 1

So here’s my code, and as I said up here it shows me an error in my SQL syntax;

function CheckDatat()
    $conn = mysqli_connect("localhost", "root", "", "hoteli") or die ("Gabim ne lidhje");
    $exp = mysqli_query($conn,"SELECT cout FROM roombook");  
    $data = date('Y-m-d');
    while($row = mysqli_fetch_array($exp))
        if ($row['cout'] <$data)
            $del = mysqli_query($conn,"DELETE * FROM roombook WHERE cout = '$row[cout]'") or die(mysqli_error($conn));

You dont DELETE * FROM, you just DELETE FROM. (You cant delete parts of rows, so there’s no point in the * )


ohhh maaaan, haha God bless you, damnnn

1 Like

You should really have a look at prepared statements to help protect yourself in these queries, rather than just concatenating strings.

At the same time, your code appears to just delete rows where the cout column is less than today, so couldn’t you lose the first query and the loop, and just do

DELETE FROM roombook where cout < CURDATE()

or have I missed something?

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.