Updating Table w/PHP -


i trying write script receives updated data script called update.php , updates database entry. code updated.php:

<?php ini_set("display_errors","on"); $dsn='mysql:host=localhost;dbname=inventory_form'; $username="****"; $password="*****"; $database="inventory_form";  $fname_val=$_post['ud_first']; $lname_val=$_post['ud_last']; $eqpmnt_brwd_val=$_post['ud_equipment_borrowed']; $service_tag_val=$_post['ud_service_tag']; $date_taken_val=$_post['ud_date_taken']; $comments_val=$_post['ud_comments']; $id_val=$_post['ud_id']; try     {     $link=new pdo($dsn, $username,$password);     echo 'connected mysql ok';     } catch (pdoexception $e)     {     $error_message=$e->getmessage();     echo "<h1>an error occurred: $error_message</h1>";     }  $query = "update inventory set fname='$fname_val', lname='$lname_val', eqmnt_brwd='$eqpmnt_brwd_val', service_tag='$service_tag_val', date_taken='$date_taken_val', comments='$comments_val' id_val='$id_val'"; $result=$link->query($query); echo "record updated"; echo $lname_val; ?> 

i receive no errors , see lname_val print out database not being updated. appreciated.

use prepared query:

$stmt = $link->prepare("update inventory                          set fname = :fname, lname = :lname, eqmnt_brwd = :eqmnt_brwd,                          service_tag = :service_tag, date_taken = :date_taken, comments = :comments                         id = :id"); $stmt->execute(array(     ':fname' => $fname_val,     ':lname' => $lname_val,     ':eqmnt_brwd' => $eqmnt_brwd_val,     ':service_tag' => $service_tag_val,     ':date_taken' => $date_taken_val,     ':comments' => $comments_val,     ':id' => $id_val)); 

this avoid problems if of values contain quotes.

also, need change

where id_val = 

to:

where id =  

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -