0

I have a basic PHP script that views data from a database and displays it on a table. I have a button on the table and I want it to call a PHP script and delete a record from the database when I click it. I get this error:

Parse error: syntax error, unexpected 'button' (T_STRING), expecting ',' or ';'

The PHP script has some code with SQL query to delete data from the table

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test";

    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }
    
    $result = mysqli_query($conn,"SELECT * FROM info");
    
    echo "<center>"; 
    echo "<table>";
    echo "<tr>";
    echo "<th>Name</th>";
    echo "<th>Email</th>";
    echo "<th>Cell</th>";
    echo "<th>quantity</th>";
    echo "<th>message</th>";
    echo "<center>";
    
    echo "</tr>";

Query database and display data. I want to call a php script when I click the button (see ajax code at the bottom)

    while ($row = mysqli_fetch_array($result))
    {
    echo "<tr>";
    echo "<td>" . $row['name'] . "</td>";
    echo "<td>" . $row['email'] . "</td>";
    echo "<td>" . $row['cell'] . "</td>";
    echo "<td>" . $row['quantity'] . "</td>";
    echo "<td>" . $row['message'] . "<button type="button">delete</button></td>";
    
    
    }
    
    
    $conn->close();

The AJAX to handle button click

    <script type="text/javascript">
        $(document).ready(function(){
            $("button").click(function(){
    
                $.ajax({
                    type: 'POST',
                    url: 'delete.php',
                    success: function(data) {
                        alert(data);
                        $("p").text(data);
    
                    }
                });
       });
    });
    </script>
Chris Haas
  • 53,986
  • 12
  • 141
  • 274
  • 2
    `echo "" . $row['message'] . " – M. Eriksson Aug 08 '22 at 13:26
  • thanx using single quotes solved the problem. – stealthcamouflougeSA Aug 13 '22 at 19:31

0 Answers0