php - How to delete data from sql with pdo? -


hello have search web day trying find example of deleting data when use pdo found mysql , mysqli , stuck can't see missing when run it give me /search.php?del=array(id). code please help

<?php   //load database connection      $host = "localhost";      $user = "abcd";      $password = "******";      $database_name = "abcd";      $pdo = new pdo("mysql:host=$host;dbname=$database_name", $user, $password, array(      pdo::attr_errmode => pdo::errmode_exception      ));  // search mysql database table          $search=$_post['search'];  $query = $pdo->prepare("select * wfuk post_code '%$search%' or telephone '%$search%'  limit 0 , 10");  $query->bindvalue(1, "%$search%", pdo::param_str);  $query->execute();  // display search result  ?>  <html>  <head>  <title> how create database search mysql & php script | tutorial.world.edu </title>  </head>  <body>  <form action="search.php" method="post">  search: <input type="text" name="search" placeholder=" search here ... "/>  <input type="submit" value="submit" />  </form>  <?php           if (!$query->rowcount() == 0) {  		 		echo "search found :<br/>";  				echo "<table style=\"font-family:arial;color:#333333;\">";	                  echo "<tr>  				<td style=\"border-style:solid;border-width:1px;border-color:#98bf21;background:#98bf21;\">first name</td>  				<td style=\"border-style:solid;border-width:1px;border-color:#98bf21;background:#98bf21;\">last name</td>  				<td style=\"border-style:solid;border-width:1px;border-color:#98bf21;background:#98bf21;\">trade</td>  				<td style=\"border-style:solid;border-width:1px;border-color:#98bf21;background:#98bf21;\">post code</td>  				<td style=\"border-style:solid;border-width:1px;border-color:#98bf21;background:#98bf21;\">telephone</td>  				<td style=\"border-style:solid;border-width:1px;border-color:#98bf21;background:#98bf21;\">comments</td>  				<td style=\"border-style:solid;border-width:1px;border-color:#98bf21;background:#98bf21;\">to use</td></tr>";			              while ($results = $query->fetch()) {  				  				echo "<tr><td style=\"border-style:solid;border-width:1px;border-color:#98bf21;\">";			                  echo $results['first_name'];  				  				echo "</td><td style=\"border-style:solid;border-width:1px;border-color:#98bf21;\">";			                  echo $results['last_name'];  				  				echo "</td><td style=\"border-style:solid;border-width:1px;border-color:#98bf21;\">";			                  echo $results['trade'];  				  				echo "</td><td style=\"border-style:solid;border-width:1px;border-color:#98bf21;\">";			                  echo $results['post_code'];  				  				echo "</td><td style=\"border-style:solid;border-width:1px;border-color:#98bf21;\">";                  echo $results['telephone'];  				  				echo "</td><td style=\"border-style:solid;border-width:1px;border-color:#98bf21;\">";                  echo $results['comments'];  				  				echo "</td><td style=\"border-style:solid;border-width:1px;border-color:#98bf21;\">";  				echo $results['id'];                  //this button delete  				echo("<button onclick=\"location.href='search.php?del=$results(id)'\">delete user</button>");                     				echo "</td></tr>";				              }  				echo "</table>";	            } else {              echo 'nothing found';          }  ?>

i start this:

    $con =  new pdo( "mysql:host=".$dbhost.";"."dbname=".$dbname, $dbusername, $dbuserpassword);      $con->setattribute(pdo::attr_errmode, pdo::errmode_exception);      $sql = "delete ".$table." id = ?";             $q = $con->prepare($sql);      $response = $q->execute(array($id));                 

Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -