0
<tr>
            <th>TH1</th>
            <th>TH2</th>
            <th>TH3</th>
            <?php
                if($account == 'admin' || $permission == 'deleting-rows')
                {
                    echo "<th><button onclick='delete_all(".$_GET['id'].")'>DELETE</button></th></tr>";
                }
            ?>
        </tr>

function delete_all(nr)
{
    if(confirm("Do you want to delete all records?"))
    {
        window.location.href="delete-all.php?id="+nr;
        return true;
    }
}

I have this kind of error in console "Uncaught SyntaxError: missing ) after argument list". But everything looks good.. Please, help.

VLAZ
  • 26,331
  • 9
  • 49
  • 67
  • When do you get this error? And what's the final rendered output of this? – VLAZ Mar 04 '20 at 14:24
  • Ignore the PHP and look at the source code in the browser. You'll be able to better see where the syntax error is coming from. – aynber Mar 04 '20 at 14:26
  • After click on this button. After click it must open "delete-all.php?id=+nr", but this is not responding – pek16448 Mar 04 '20 at 14:26
  • Also, for reference `window.location.href="delete-all.php?id="+nr;` - you seem to be using a GET request to introduce changes to the application. This is very much discouraged - GET should only be retrieving data without changing anything, while POST (and possibly PUT, DELETE) would be doing the changes. The simplest reason is that if a web crawler tries to index your `delete-all.php?id=1`, `delete-all.php?id=2`, `delete-all.php?id=3`, etc pages, you'd lose all data. – VLAZ Mar 04 '20 at 14:27
  • 2
    `delete_all(".$_GET['id'].")` maybe the `id` is not really a real number. In that case you have to pass it as string. – Lain Mar 04 '20 at 14:27
  • @Lain "id" is IP address. But in browser it looks "delete_all(x.x.x.x)" as normal IP Adress – pek16448 Mar 04 '20 at 14:34
  • 1
    @pek16448 then you have invalid JS, since `1.2.3.4` is not a valid numeric literal. You need to pass this as a string. – VLAZ Mar 04 '20 at 14:37
  • @JayBlanchard - the syntax error is not in the PHP code itself but the JavaScript code that PHP produces. – VLAZ Mar 04 '20 at 14:48

0 Answers0