PHP with JS implementation Click Hyperlink to perform delete confirmation operation, JS hyperlink _php Tutorial

Source: Internet
Author: User
Tags dsn php get url switch case

PHP with JS Implementation Click on the hyperlink to perform delete confirmation operation, JS hyperlink


Title, this time is to implement the Click Hyperlink implementation of the JS code, and confirm whether to delete database data, using PHP.

First, link the database, query the database data:

Copy the Code code as follows:
<?php
$dbms = ' MySQL '; Database type, for developers, use different databases, just change this, don't remember so many functions
$host = ' localhost '; Database host Name
$dbName = ' db_database19 '; The database used
$user = ' root '; Database connection user Name
$pass = ' root '; The corresponding password
$DSN = "$dbms: host= $host;d bname= $dbName";
try {
$pdo = new PDO ($DSN, $user, $pass); Initializes a PDO object, which is the creation of a database connection object $pdo
$query = "SELECT * from Tb_pdo_mysql"; Defining SQL statements
$result = $pdo->prepare ($query); Preparing query statements
$result->execute (); Executes a query statement and returns a result set
while ($res = $result->fetch (PDO::FETCH_ASSOC)) {//while loops out the query result set and sets the result set as the associated index
?>

<?php echo $res [' id '];? >
<?php echo $res [' Pdo_type '];? >
<?php echo $res [' database_name '];? >
<?php echo $res [' dates '];? >
) "> Delete

<?php
}
} catch (Pdoexception $e) {
Die ("error!:". $e->getmessage (). "
");
}
?>

Call a JavaScript method at hyperlink Delete, passing the record Id,js method is:

Copy the Code code as follows:

To delete a database record code:

Copy the Code code as follows:
<?php
if (@$_get[' conn_id ']!= "") {
$dbms = ' MySQL '; Database type, for developers, use different databases, just change this, don't remember so many functions
$host = ' localhost '; Database host Name
$dbName = ' db_database19 '; The database used
$user = ' root '; Database connection user Name
$pass = ' root '; The corresponding password
$DSN = "$dbms: host= $host;d bname= $dbName";
try {
$pdo = new PDO ($DSN, $user, $pass); Initializes a PDO object, which is the creation of a database connection object $pdo
$pdo->setattribute (pdo::attr_errmode,pdo::errmode_exception);
$query = "Delete from tb_pdo_mysql where Id=:id";
$result = $pdo->prepare ($query); Pre-prepared statements
$result->bindparam (': Id ', $_get[' conn_id '); Binding the updated data
$result->execute ();
} catch (Pdoexception $e) {
Echo ' PDO Exception caught. ';
Echo ' Error with the database:
';
Echo ' SQL Query: '. $query;
Echo '

';
echo "Error:". $e->getmessage (). "
";
echo "Code:". $e->getcode (). "
";
echo "File:". $e->getfile (). "
";
echo "line:". $e->getline (). "
";
echo "Trace:". $e->gettraceasstring (). "
";
Echo '
';
}
}
?>

This code is placed at the very beginning of the body portion of the HTML page and, at worst, before the query record code.


Rookie php JS confirm Delete Code Click Link, pop-up window, including PHP get get feedback of the entire code, on-line only JS part of the

Oh, this simple ah,
Delete </a>
Click OK to jump directly to the delete page.
The point cancellation is not moving.
PHP Get URL parameters
$id = $_get[id];
If there is nothing to understand, can really through the Baidu hi to my message.

PHP, click on hyperlink text, turn to implement delete/change MySQL data

Delete </a>

When foreach iterates through the data, it writes the ID value and then delete.php the page to perform the delete operation.
Either you include the database page in the delete.php (not recommended)
Either it is written on a page, then the switch case determines that the operation accepts the ID and then executes
Delete </a> This is a more recommended
In the delete.php page
Connect the database switch ($act =$_get[' Act ']) {case ' del ': ...; Break;case ....}

http://www.bkjia.com/PHPjc/904015.html www.bkjia.com true http://www.bkjia.com/PHPjc/904015.html techarticle PHP with JS implementation Click on the hyperlink to perform delete confirmation operation, JS hyperlink title, this time is to implement the Click Hyperlink Implementation of JS code, and confirm whether to delete database data, using ...

  • Related Article

    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.