UPDATE query + using GET & POST method at once?
Hi everyone here, I have a table that its content is what I have in DB (mine: easyPHP), here I wanted to edit the content of the table in browser & then by clicking the update button, I should get success to update the new information in my Data Base. in my <form> I've used POST method before for another purposes I had before, but now for UPDATE I need to use GET method. I'm actually new in PHP & PDO & everything. I think that I've tried myself to figure out how to write UPDATE query or how to use POST & GET method together, but when I run code , I get no Error! but also with no results. I get confused! I need your help.Thank you
here I show you my code (but not the full code, cause it's not necessary) :
this one is my form:
& this one is what I've tried to write the UPDATE query:
<form method="POST" action="index.php?get=variables">
<table border="1 solid #000000">
<td>content of task</td>
$MyTask = "SELECT id,title, content_task FROM `task` " ;
$task_panel = $query->fetchAll(PDO::FETCH_ASSOC);
// Array ( [title] => web  => web [content_task] => task  => task )
// Array ( [title] => web [content_task] => task )
// print_r ($query->fetchAll(PDO::FETCH_ASSOC));
$n = 0;
foreach($task_panel as $row)
<td><input name="checkbox" type="checkbox" value="'.$row['id'].'"></td>
<!--<td><button name="edit" type="submit" value="'.$row['id'].'">edit</td>-->
<td><button name="update" type="submit" value="'.$row['id'].'">update</td>
<button type="submit" name="delete" value="delete">delete</button>
if($_SERVER['REQUEST_METHOD'] == 'GET')
$update = $_GET['update'];
$up_id = implode(',', $update);
$upt = "UPDATE task SET `title` =:'title', `content_task`=:'content_task' WHERE id IN ($up_id)";
$upp = $conn->prepare($upt);
Why are you checking for GET when your form tag says method="POST"?
Also, the ":" character needs to be inside of the quotes in the query, e.g. ':title', not :'title'. However, that then means you have to bind those parameters to a PHP variable, either via the PDOStatement::bindParam() method, or by using them as keys in an array of input data as the second argument to PDOStatement::execute().
well, I should use GET, cause it's a task that someone offers me to do to learn it, it can be good for me , cause in this way I would learn how to use both GET & POST together. & about UPDATE query I have no idea how to change it if necessary. & I surely know there's something wrong about 'update', cause it seems changes cannot be set in data base.
You should only use GET for read-only requests. Since this is an update request which will change data, POST is the correct option. (One reason being that if it's done as a GET request, the user can bookmark the resulting URL, and accidentally (or intentionally) just keep doing the same update every time s/he selects that bookmark or refreshes the page, without any indication that that is what will happen.) But if you really feel the need to use GET for educational purposes, just change the form tag's method value to "GET".
If unsure about how to handle bound parameters in PDO, the manual is your best friend.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread