php - Deleting a ROW from MySQL database using MySQLi -
i've got delete.php
file yes/no buttons call deleterecord.php
delete selected row database.
the problem seems i'm not passing variable projectid
through deleterecord file.
can please tell me what's wrong?
delete.php
<?php error_reporting(e_all|e_strict); ini_set('display_errors', true); require('includes/conn.inc.php'); require('includes/functions.inc.php'); $sprojectid = safeint($_get['projectid']); $stmt = $mysqli->prepare("select projectid, projectname, projectimage, languageused, applicationused, description projects projectid = ?"); $stmt->bind_param('i', $sprojectid); $stmt->execute(); $stmt->bind_result($projectid, $projectname, $projectimage, $languageused, $applicationused, $description); $stmt->fetch(); $stmt->close(); ?> <!doctype html> <input name="projectid" type="hidden" value="<?php echo $projectid; ?>"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>delete <?php echo $projectname; ?></title> <link href="styles/cms.css" rel="stylesheet" type="text/css"> </head> <body> <div id="container"> <header> <h1>delete <?php echo $projectname; ?></h1> <?php require('includes/nav.inc.php'); ?><p>hello </p><?php echo "$sprojectid" ?> </header> <form name="form1" method="get" action="process/deleterecord.php"> <p>are sure wish delete <?php echo $projectname; ?>?</p> <p> <input type="submit" name="del" id="del" value="delete"> </p> </form> <form name="form2" method="" action="listall.php" id="saveform"> <input type="submit" name="save" id="save" value="save"> </form> <?php require('includes/footer.inc.php'); ?> </div> </body> </html>
deleterecord.php
<?php error_reporting(e_all|e_strict); ini_set('display_errors', true); require('../includes/conn.inc.php'); require('../includes/functions.inc.php'); // sanitize user variables $sprojectid = safeint($_post['projectid']); // prepare sql $stmt = $mysqli->prepare("delete projects projectid = ?"); $stmt->bind_param('i', $sprojectid); $stmt->execute(); $stmt->close(); //header("location: ../index.php"); // redirect browser exit; // make sure no other code executed ?>
you need write hidden field inside form , change method post
.
<form name="form1" method="post" action="process/deleterecord.php"> <p>are sure wish delete <?php echo $projectname; ?>?</p> <p> <input name="projectid" type="hidden" value="<?php echo $projectid; ?>"> <input type="submit" name="del" id="del" value="delete"> </p> </form>
as per @volkerk comment below, put input element "within" form element instead of 1 before <html>
tag.
Comments
Post a Comment