php - fill in forms from an edit row results in a white page -
i have code have been working , @ impass every time click on edit row page passes on id number fill form on page issue white page no source code
the code supposed grab db , populate form can update records
<?php // connect database include("connect-db.php"); // creates edit record form function renderform($commentfrom = '', $email ='', $date ='', $about = '', $reply = '', $comments ='', $nnnread = '', $habsread = '', $directorscomments='', $error, $id = '') { ?> <!doctype html public "-//w3c//dtd html 4.01//en" "http://www.w3.org/tr/html4/strict.dtd"> <html> <head> <title> <?php if ($id != '') { echo "edit record"; } else { echo "new record"; } ?> </title> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> </head> <body> <h1><?php if ($id != '') { echo "edit record"; } else { echo "new record"; } ?></h1> <?php if ($error != '') { echo "<div style='padding:4px; border:1px solid red; color:red'>" . $error . "</div>"; } ?> <form action="" method="post"> <div> <?php if ($id != '') { ?> <input type="hidden" name="id" value="<?php echo $id; ?>" /> <p>id: <?php echo $id; ?></p> <p>date: <?php echo $date; ?></p> shg player name(required):<input type="text" name="commentfrom" required="required" value="<?php echo $commentfrom; ?>"/> </br> email address(required): <input type="text" name="email" required="required" value="<?php echo $email; ?>"/> </br> date submitted <?php echo $id; ?> player or host about: <input type="text" name="about" value="<?php echo $about; ?>"/> </br> require director contact you?:<p> <input type="text" name="reply" value="<?php echo $reply; ?>"/> <br/> please include comments here:</br><textarea name="comments" rows="10" cols="25"value="<?php echo $comments; ?>"/></textarea></br> nnn read <input id="nnnread" type="text" value="<?php echo $nnnread; ?>"/></br> habs read <input id="habsread" type="text" value="<?php echo $habsread; ?>"/></br> directors comments :</br><textarea name="directorscomments" rows="10" cols="25" value="<?php echo $directorscomments; ?>"/></textarea></br> category <input id="category" type="text" value="<?php echo $category; ?>"/></br> <p>* required</p> <input type="submit" name="submit" value="submit" /> </div> </form> </body> </html> <?php } /* edit record */ // if 'id' variable set in url, know need edit record if (isset($_get['id'])) { // if form's submit button clicked, need process form if (isset($_post['submit'])) { // make sure 'id' in url valid if (is_numeric($_post['id'])) { // variables url/form $id = $_post['id']; $commentfrom = htmlentities($_post['commentfrom'], ent_quotes); $email = htmlentities($_post['email'], ent_quotes); $date = $_post['date']; $about = htmlentities($_post['about'], ent_quotes); $reply = htmlentities($_post['reply'], ent_quotes); $comments = htmlentities($_post['comments'], ent_quotes); $nnnread = htmlentities($_post['nnnread'], ent_quotes); $habsread = htmlentities($_post['habsread'], ent_quotes); $directorscomments = htmlentities($_post['directorscomments'], ent_quotes); $category = htmlentities($_post['category '], ent_quotes); // check commentfrom , email both not empty //if ($commentfrom == '' || $email == '') { // if empty, show error message , display form $error = 'error: please fill in required fields!'; renderform($id, $commentfrom, $email, $date, $about, $reply, $comments, $nnnread, $habsread, $directorscomments, $category); } { // if fine, update record in database if ($stmt = $mysqli->prepare("update comments set commentfrom = ?, email = ?, = ?, reply = ?, comments = ?, nnnread = ?, habsread = ?, directorscomments = ?, category = ? id=?")) { $stmt->bind_param("ssi", $commentfrom, $email, $date, $about, $reply, $comments, $nnnread, $habsread, $directorscomments, $category, $id); $stmt->execute(); $stmt->close(); } // show error message if query has error else { echo "error: not prepare sql statement."; } // redirect user once form updated header("location: directorsinfo.php"); } } // if 'id' variable not valid, show error message else { echo "error!"; } } // if form hasn't been submitted yet, info database , show form else { // make sure 'id' value valid if (is_numeric($_get['id']) && $_get['id'] > 0) { // 'id' url $id = $_get['id']; // recod database if($stmt = $mysqli->prepare("select * comments id=?")) { $stmt->bind_param("i", $id); $stmt->execute(); $stmt->bind_result($id, $commentfrom, $email, $date, $about, $reply, $comments, $nnnread, $habsread, $directorscomments, $category); $stmt->fetch(); // show form renderform($commentfrom, $email, $about, $reply, $comments, $nnnread, $habsread, $directorscomments, $category, $id); $stmt->close(); } // show error if query has error else { echo "error: not prepare sql statement"; } } // if 'id' value not valid, redirect user directorsinfo.php page else { header("location: directorsinfo.php"); } } } $mysqli->close(); } ?>
Comments
Post a Comment