PHP Delete Record implementation code _php tips

Source: Internet
Author: User
Copy Code code as follows:

<?php
@mysql_connect ("localhost", "root", "1981427")//Select database before you need to connect to the database server
Or Die ("Database server Connection Failed");
@mysql_select_db ("test")//Select Database MyDB
Or Die ("database does not exist or not available");
$query = @mysql_query ("SELECT * from TableName1")//Execute SQL statement
Or Die ("SQL statement execution failed");
echo "<form method= ' post ' name= ' Form1 ' action= ' delete_do.php ' >";
echo "<table border=1>";
Output all records from line No. 0 to largest row in a circular fashion
for ($i =0; $i <mysql_numrows ($query); $i + +)
{
$id = mysql_result ($query, $i, ' id '); Output the Serial_no column of line $i
$username = mysql_result ($query, $i, ' username '); Output the Name column of the $i row
$password = mysql_result ($query, $i, ' password '); Output the salary column of line $i
echo "<tr>";
echo "<td><input type= ' checkbox ' name= ' chk[] ' value= ' $id ' ></td> ';
echo "<td> $id </td>";
echo "<td> $username </td>";
echo "<td> $password </td>";
echo "</tr>";
}
echo "<tr>";
echo "<td colspan=4 nowrap><input name= ' submission ' type= ' submit ' value= ' submitted ' > ';
echo "<input type= ' reset ' name= ' reset ' value= ' reset ' ></td>";
echo "</tr></table></form>";
?>


Copy Code code as follows:

<?php
@mysql_connect ("localhost", "root", "1981427")//Select database before you need to connect to the database server
Or Die ("Database server Connection Failed");
@mysql_select_db ("test")//Select Database MyDB
Or Die ("database does not exist or not available");
foreach ($_post[' chk '] as $check)
{
$query = mysql_query ("Delete from tablename1 where id = $check");
if ($query)
echo "Delete Success";
Else
echo "Delete Failed";
}
Mysql_close ();
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.