0
if ($result->num_rows > 0)
{
    // output data of each row
    while($row = $result->fetch_assoc())
    {
        $ID = $row["companyId"];
        $_sql_update_company = "
            UPDATE Table
            SET companyName = '$Company->Name', companyCity = '$Company->City', companyURL = '$Company->Url'
            WHERE companyId = '$ID'";

        $_result_update = $conn->query($_sql_update_company);
        echo ('Modified an existing row ID:'. $ID .'<br />');
    }
}
else...

I have this piece of code, the script is going through the right loop at the right time(if the row exists it goes through this while loop, and if the row does not exist, it goes with the else. Seems like the problem is with the query $_sql_update_company. It just does not set new values, but still echoes "Modified an existing row...". Am I writing the SET with a wrong syntaxe? (i also tried without '')

lazaa
  • 3
  • 3
  • See here how to get the [actual mysqli error](https://stackoverflow.com/questions/22662488/mysqli-fetch-assoc-expects-parameter-call-to-a-member-function-bind-param/22662582#22662582). – El_Vanja Mar 04 '21 at 11:37
  • 1
    And please consider switching to prepared, parametrized statements to [prevent SQL injection](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php). – El_Vanja Mar 04 '21 at 11:38
  • You might also consider the [`INSERT... ON DUPLICATE KEY UPDATE`](https://dev.mysql.com/doc/refman/8.0/en/insert-on-duplicate.html) mechanism. – El_Vanja Mar 04 '21 at 11:42

0 Answers0