Jump to content

Put a button front of cell rows from a PHP echoed table and click on specific row to fill a form


referag

Recommended Posts

Hi everybody!Im newbie to php. please,suppose we have a MYSQL DATABASE with table CUSTOMERS.In the page: addCustomer.php, we echoed this table and it returned us a number of rows.on the same page, we have a form that contains empty fields. (name, birth, adress).Questions:How to add a button front of each displayed row? and how to when we click on the related button we fill the content of the form and submit it to the table CUSTOMERS.

 

we want to verify if the customer exists when echoing...if so we click on the relative row, and the form is filled. if no we fill the form manually

 

thanks

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><title>Untitled Document</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css"><!--.style2 {font-size: 36px}.style4 {font-size: 24px}#hauttableau {    background-color:black;    color:white;    text-align:center;    padding:5px;}--></style><script language="JavaScript" type="text/JavaScript"><!--function MM_reloadPage(init) {  //reloads the window if Nav4 resized  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();}MM_reloadPage(true);//--></script></head><body><p align="left" class="style2">NOUVEAU CLIENT </p><form name="form1" method="post" action="insert_pdo_ajout_client.php">  <p class="style4"></p>  <p><span class="style4">CLIENT</span>      </p>    <p>    NOM CLIENT<input name="nomclientField" type="text" id="nomclientField">  <p>    PRENOM         <input name="prenomclientField" type="text" id="prenomclientField">   <p>ADRESSE       <input name="adresseclientField" type="text" id="adresseclientField"></p>  <p>DATE NAISSANCE     <input name="datedenaissanceField" type="text" id="datedenaissanceField"></p>  <p>    CIN     <input name="cinclientField" type="text" id="cinclientField"> </p>  <p>TEL     <input name="telclientField" type="text" id="telclientField2">         </p>  <p>    <input type="submit" name="Submit" value="ENREGISTRER">      </p></form><p class="style2"> </p><?phpecho "<table style='border: solid 2px black;' class= 'hauttableau'>";  echo "<tr><th>Id</th><th>Firstname</th><th>Lastname</th></tr>";class TableRows extends RecursiveIteratorIterator {     function __construct($it) {         parent::__construct($it, self::LEAVES_ONLY);     }     function current() {         return "<td style='width: 150px; border: 1px solid black;'>" . parent::current(). "</td>";     }     function beginChildren() {         echo "<tr>";     }     function endChildren() {         echo "</tr>" . "n";     }}$servername = "localhost";$username = "root";$password = "root";$dbname = "zg";try {     $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);     $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);     $stmt = $conn->prepare("SELECT idclient, nomclient,prenomclient,datedenaissanceclient,adresseclient, cinclient,telclient FROM client");     $stmt->execute();     // set the resulting array to associative     $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);     foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {         echo $v;     }}catch(PDOException $e) {     echo "Error: " . $e->getMessage();}$conn = null;echo "</table>";?> </body></html>
Link to comment
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
×
×
  • Create New...