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.

3
  • Is there a reason you are starting with PHP rather than NodeJS? Commented Dec 9, 2012 at 23:17
  • yeah, my class focuses on php and mySQL Commented Dec 10, 2012 at 2:34
  • Shame. NodeJS is the future. I would recommend rendering the contents of the array within the page and the. Just posting it back Commented Dec 10, 2012 at 3:12

2 Answers 2

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'.

Sign up to request clarification or add additional context in comments.

1 Comment

why you're planting an SQL injection in almost every example?
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();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.