PHP MVC Delete Function Controller -
i have made mvc site displaying databases records, each record printed on own line delete button beside it. having issues delete button. when click delete button trying sending controller handle.
the issues having are
- i cant send row id button.php controller (have strong suspicion code wrong)
the delet function in controller doesnt work, in code below have hard coded in row id want delete when click delete button following error
syntax error in sql statement.you have error in sql syntax; check manual corresponds mysql server version right syntax use near 'id=27' @ line 1
button.php
<?php $result=$itemsdao->getitems(); foreach ($result $row) { $uid = $row['id']; ?> <form action="index.php" method="post"> <fieldset> <input id='action' type='hidden' name='action' value='deleteitem' /> <p> <div class="form-group"> <div class="controls"> <input type="hidden" id="fid" name="uid" value="<?php echo $uid; ?>"> <input type="submit" class="btn btn-success" value="delete"> </div> </div> </p> </fieldset> </form> <?php } ?>
delete function in controller
function deleteitem($parameters) { $id = $parameters["fid"]; if ($this->model->deleteitem( $id )) { $this->model->hasdeletefailed = false; $this->model->setdeleteitemconfirmation(); return (true); } else $this->model->deleteitemerror ( delete_item_error_str ); }
delete sql
public function deleteitem($id) { $delid = $id; $sqlquery = "delete items"; $sqlquery .= " id=$delid;"; $result = $this->getdbmanager () -> executequery ( $sqlquery ); }
try steps :
- check whether
$parameters
passeddeleteitem
function (useecho $parameters
or somthing) - if check query (
delete * 'thetable' id = $id
)
normally in mvc site parameters pass through (site_url/controller/method/parameter
) url. while using form, it's need mechanism capture form variables.
Comments
Post a Comment