Click here to Skip to main content
14,691,476 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
include 'conn.php';

$result = ("SELECT * FROM usrdata"); // selecting data through mysql_query()

echo'<table border=1px>';  // opening table tag
echo'<th>id</th><th>email</th><th>Password</th>'; //table headers

while($data = mysqli_fetch_array($count))
// we are running a while loop to print all the rows in a table
echo'<tr>'; // printing table row
echo '<td>'.$data['id'].'</td><td>'.$data['email'].'</td><td>'.$data['password'].'</td>'; // we are looping all data to be printed till last row in the table
echo '<td><input type="button" name="delete" value="delete"></td>';


echo'</tr>'; // closing table row
echo '</table>';


    function delete()
    	$delete1 =("DELETE FROM `usrdata` WHERE id = '$id'");
        $result = mysqli_query($conn,$delete1) or die(mysqli_error());
	echo "record deleted";


What I have tried:

i am try to delete entire row into table using button click. but button is clikced event is dosen't responsed
Updated 30-Jan-20 0:11am

$delete1 =("DELETE FROM `usrdata` WHERE id = '$id'");
$id is nowhere defined.

You might pass the ID as value parameter for the delete button.
Aside from Jochen Arndt's suggestion, function delete() uses $conn - but that value is defined outside of its scope. You don't have a connection.

You need something like function($conn) {} so you can pass in the connection.
Jochen Arndt 12-Jan-18 7:56am
I think that $conn is in global scope by including 'conn.php'.
W Balboos, GHB 12-Jan-18 8:00am
They may well be - no way to tell (or did I miss something?).
If I didn't miss something, than that base is now covered.

All the usage of $conn that 'must have worked' is in the same code block as the #include - but once you create the function - maybe yes, maybe no. (?)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900