Friday, 15 January 2010

mysqli - php update dynamic sql rows through form -



mysqli - php update dynamic sql rows through form -

my goal retrieve dynamic sql list of rows , edit every item in list within same page using post (no multiple changes @ 1 time required). can achieved within same page? made script below displays way want to, switch statement doesn't seem fit purpouse.

i aware code might not best practice (not mention secure). sorry beingness inflexible, i'm not allowed utilize other php/html

code:

<?php if ($result->num_rows > 0) { // output info of each row while($row = $result->fetch_assoc()) { echo '<tr> <td class="tg">' .$row["id"]. '</td>' . "\n"; echo '<td class="tg"> <form action= "" method="post"> <input type="text" name="voornaam" value="'.$row["voornaam"].'" style="width:100px"> <input name="submit" type ="submit" value="aanpassen"><br/><br/>' . '</td>' . "\n"; echo '<td class="tg"> <form action= "" method="post"> <input type="text" name="voornaam" value="'.$row["achternaam"].'" style="width:100px"> <input name="submit" type ="submit" value="aanpassen"><br/><br/>' . '</td>' . "\n"; echo '<td class="tg"> <form action= "" method="post"> <input type="text" name="voornaam" value="'.$row["omschrijving"].'" style="width:500px"> <input name="submit" type ="submit" value="aanpassen"><br/><br/>' . '</td> </tr>' . "\n"; } } else { echo "0 resultaten"; } switch(!empty($_post)) { case !empty($_post[$row["voornaam"]]): // update sql query 'firstname' here break; } $conn->close(); ?>

by way actualy see editing , it's more clean.

// pdo db conecction (secure way) seek { $con = new pdo("mysql:host={$host};dbname={$db_name}", $username, $password); $con->setattribute(pdo::attr_errmode, pdo::errmode_exception); }catch(pdoexception $exception){ //to handle connection error echo "connection error: " . $exception->getmessage(); } if isset($_post["voornaam"]){ $stmt = $con->prepare(" query"); $stmt->execute(); echo "yeah did it"; } else { stmt = $con->prepare(" query"); $stmt->execute(); $rows = $stmt->fetchall(); foreach ($rows $rs) { $voornaam = $rs["voornaam"] $achternaam = $rs["achternaam"] $omschrijving = $rs["omschrijving"] } } // illustration echo '<form action= "" method="post"> <input type="text" name="voornaam" value="'. $voornaam .'" style="width:100px"><input name="submit" type ="submit" value="submit"><br/><br/>';

value input can have 1 submit button @ end cause other info overwritten itself.

php mysqli

No comments:

Post a Comment