Jump to content
Sign in to follow this  
mohammadgholeh

Delete row from html table using ajax,php and sql

Recommended Posts

Hello,

I need delete row in html table select row and click button delete make delete using ajax Currentally can make delete without ajax but I need delete row and stay on page without make submit on other page

 

code html,php

<?php

$resualt=mssql_query("SELECT * FROM Address where user_id='$UserId' ") ;echo "<table border='1' class='imagetable' id='imagetable'width='400px' >n";echo '<thead>'.'<tr>';echo '<th>Street</th>'.'<th>Quarter</th>'.'<th>From</th>'.'<th>To</th>'.'<th>Notes</th>';echo '</tr>'.'</thead>';echo '<tbody>';while ($row = mssql_fetch_assoc($resualt)) {$fromDate=$row['from_date'];$toDate=$row['to_date'];echo " <tr onClick='myPopup($row[id])'". ( $_GET['id'] == $row['id'] ? "style='background-color: green;'":"").">n"."<td >{$row['street']} </td>n"."<td>{$row['quarter']}</td>n"."<td>$fdate2</td>n"."<td>$tdate2</td>n"."<td>{$row['other_info']}</td>n";}echo '</tbody>';echo "</table>n";?>

//button delete <?phpecho"<a class='button-link' href='delete_address.php?id=$id'>delete</a>";

?>

 

code sql to make delete from db

<?php$idEmploye=$_GET['id'];$db_host = 'jo';$db_username = 'jo1';$db_password = '123321';$db_name = 'db_test';mssql_connect($db_host, $db_username, $db_password);mssql_select_db($db_name);mssql_query("DELETE FROM AddressWHERE id='$idEmploye' ; ") or die(mssql_error()) ;echo '<script language="javascript">';echo 'alert("successfully deleted ")';echo '</script>';echo "<script>setTimeout("location.href ='address.php';",10); </script>"; ?>

Any Help Thanks

Share this post


Link to post
Share on other sites

Have you looked at any ajax tutorials to get started? Note that your code is open to SQL injection attacks. If you go to delete_address.php?id=%27+OR+%271%27%3D%271 then it will delete everything in the address table. If you go to delete_address.php?id=%27%3B+DROP+TABLE+Address%3B+-- then it will remove the entire address table from the database.

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×