0

I've created a database for one of my classes simulating a hotel reservation form.
my database table name that I am trying to get values from is tblNameRes and the fields are fldName and pkEmail I have gotten the values from the database and displayed them in this table here: http://www.uvm.edu/~cchessia/cs148/assign4/strugg.php

I want to add a column to be able to update and delete these records, but I don't really understand how. I have this code:

$updating = $db->prepare('UPDATE `tblNameRes` SET `name` = `name` + ? WHERE `id` = ?');
$updating->execute(array(20, $id));

but I want to be able to click a link that says "update" and it will take me to another page that allows me to edit the data and submit it back to the database. I would also like to be able to delete the data in the same way.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Caroline
  • 9
  • 2

2 Answers2

1

I'm a little confused to what you would like, would you like the PDO code to both update and delete items from your DB? If so I use this, I'm also new to PDO. Also try not to use ' around table/field names.

/** Code to update */

$query = "UPDATE tblNameRes SET name ='$name' WHERE id = :id";
$stmt = $db->prepare($query);
$stmt->BindValue(':id', $id, PDO::PARAM_INT);
$stmt->execute();

/** Code to delete */

$query = "DELETE FROM tblNameRes WHERE id = :id";
$stmt = $db->prepare($query);
$stmt->BindValue(':id', $id, PDO::PARAM_INT);
$query->execute();

Let me know if this helps, or is not what you wanted. I'm new here so I can't post 'comments'.

James
  • 255
  • 1
  • 10
0

/* code for update and remove this 'at the beginning an at the end*/

$query = "UPDATE tblNameRes SET name =:fname WHERE id = :id"; $stmt = $db->prepare($query); $stmt->BindValue('fname',$fname); $stmt->execute();

Relexk
  • 29
  • 1