why my cannot edit/update database using PHP? -
here code. in code, when edit , "update" data in database using php, doesn't change data in database or myphpadmin. take @ below code:
<?php include("dataconn.php"); //connect database external php. if($_session["loggedin"]!="true") header("location:admin_login.php"); $aid=$_session["userid"]; $admin_info="select * admin ad_id='".$aid."'"; if(isset($_post["savebtn"])) { $adname=$_post["name"]; $adaddress=$_post["address"]; $ademail=$_post["email"]; $adcontact=$_post["contact"]; mysql_query("update admin set ad_name='".$ad_name."',address='".$adaddress."',email='".$ademail."',contact_num='".$adcontact."' ad_id=$aid"); header("location:profile.php"); } ?> <body> <form name="edit" method="post" action=""> <tr> <th class="title">name</th> <td>:</td> <th><input type="text" size="50" value="<?php echo $row["ad_name"]?>" name="name"/></th> </tr> <tr> <th class="title">address</th> <td>:</td> <th><input type="text" size="50" value="<?php echo $row["address"];?>" name="address" /></th> </tr> <tr> <th class="title">email</th> <td>:</td> <th><input type="text" size="50" value="<?php echo $row["email"];?>" name="email"/></th> </tr> <tr> <th class="title">contact number</th> <td>:</td> <th><input type="text" size="50" value="<?php echo $row["contact_num"];?>" name="contact"></th> </tr> <table> <span id="edit"><input type="submit" name="savebtn" value="save/change"/></span> </form> </body> </html>
i have tried fix numerous times,but still has same problem. can me?
to finfing error:
<?php echo $adname . '<br />'; echo $adaddress . '<br />'; echo $ademail . '<br />'; echo $adcontact . '<br />'; $result = mysql_query("update admin set ad_name='".$ad_name."',address='".$adaddress."',email='".$ademail."',contact_num='".$adcontact."' ad_id=$aid"); if (!$result) { die('invalid query: ' . mysql_error()); }else{ //header("location:profile.php"); echo "success"; } ?>
and try change code pdo, this:
<?php if(isset($_post["savebtn"])){ $adname=$_post["name"]; $adaddress=$_post["address"]; $ademail=$_post["email"]; $adcontact=$_post["contact"]; try { $pdo = new pdo('mysql:host=localhost;dbname=somedatabase', $username, $password); $pdo->setattribute(pdo::attr_errmode, pdo::errmode_exception); $stmt = $pdo->prepare('update admin set ad_name=:adname ,address = :adaddress , email = :ademail , contact_num = :adcontact ad_id = :aid'); $stmt->execute(array( ':adname' => $adname, ':adaddress' => $adaddress, ':ademail' => $ademail, ':adcontact' => $adcontact, ':aid' => $aid )); header("location:profile.php"); } catch(pdoexception $e) { echo 'error: ' . $e->getmessage(); } } ?>
Comments
Post a Comment