mysql - How to display fetched result inside php form? -
i php mysql beginner! trying id (primary key) value of row , update corresponding values in database. search results working perfecting , getting redirected update form page, in wanted display fetched result, can edit result , update values.
my php
<?php require_once 'db_alternate2.php'; session_start(); try{ $conn = new pdo("mysql:host=$host;dbname=$dbname", $username, $password); if( isset($_get['edit']) ) { $id = $_get['edit']; $res= "select * staff_db staff_id='$id'"; $r = $conn->query($res); $r->setfetchmode(pdo::fetch_assoc); } if( isset($_post['new_staf_id']) && isset($_post['new_staf_name']) && isset($_post['new_staf_acc']) && isset($_post['new_staf_bnkaddrs']) ) { $staf_id = $_post['new_staf_id']; $staf_name = $_post['new_staf_name']; $staf_acc = $_post['new_staf_acc']; $staf_bnkaddrs = $_post['new_staf_bnkaddrs']; $sql = $conn->prepare("update staff_db set staff_id='$staf_id' staff_name='$staf_name' staff_acc='$staf_acc' staff_bnkaddrs='$staf_bnkaddrs' sl_no ='$id'"); $sql->execute(); $result1 = $sql->fetch(pdo::fetch_assoc); echo "<meta http-equiv='refresh' content='0;url=staff_update.php'>"; } } catch (pdoexception $pe) { die("could not connect database $dbname :" . $pe->getmessage()); } ?> .
my html
<form class="" style="right:10px !important;" action="staff_db.php" method="post"> <div class="main-left" style="width:38% !important; margin-left:100px;"> <p>staff id:</p> <input type="text" name="staf_id" value="______"/> <p>name:</p> <input type="text" name="staf_name" value="______"/> </div> <div class="main-right" style="width:38% !important; margin-right:100px;"> <p>account no:</p> <input type="text" name="staf_acc" value="______"/> <p>bank address:</p> <input type="text" name="staf_bnkaddrs" value="______"/> </div> <div class="bottom-centre" style="padding-top:50px; "> <input class="submit" type="submit" value="update"/> </div> </form>
i know simple question, guide me here! how display pdo fetched results inside value="______" of form.
thanks in advance!
just few modifications in code
if( isset($_get['edit']) ) { $id = $_get['edit']; $res= "select * staff_db staff_id='$id'"; $r = $conn->query($res); $r->setfetchmode(pdo::fetch_assoc); $result = $r->fetch(); }
and few modification in form put value
<input type="text" name="staf_name" value=<?php echo $result["staff_name"]; ?>/>
Comments
Post a Comment