PHP Very Very Urgent edit form will not work

Help,
 I told everyone I had finished ..I thought I had  finished ( with help of ee) my first php project. IT WAS Working, what happened , what did I do, why didnt I leave it alone. I cannot find whats wrong . Its not bringing up any errors

<?php
include('corefuncs.php');
// remove backslashes
nukeMagicQuotes();
// initialize flags
$OK = false;
$done = false;
 // create database connection
$conn = new mysqli('localhost','dodgy', 'dodgy1', 'dodgy2' ) or die ( 'cannot opendb');

// get details of selected record
if ($_GET && !$_POST) {
  // prepare SQL query
  $sql = 'SELECT article_id, image_id, bname, bdesc, price
          FROM journal WHERE article_id = ?';
  // initialize statement
  $stmt = $conn->stmt_init();
  if ($stmt->prepare($sql)) {
    // bind the query parameters
    $stmt->bind_param('i', $_GET['article_id']);
      // bind the results to variables
      $stmt->bind_result($article_id, $image_id, $bname, $bdesc, $price);
      // execute the query, and fetch the result
      $OK = $stmt->execute();
      $stmt->fetch();
      // free the database resources for the second query
      $stmt->free_result();
      }
  // get details of the images
  $getImages = 'SELECT * FROM images ORDER BY filename';
  $imageList = $conn->query($getImages) or die(mysqli_error($conn));
  }
// if form has been submitted, update record
if (array_key_exists('update', $_POST)) {
  $sql = 'UPDATE journal SET image_id = ?, bname = ?, bdesc = ?, price = ? WHERE article_id = ?';
  $stmt = $conn->stmt_init();
  if ($stmt->prepare($sql)) {
    $stmt->bind_param('issis', $_POST['image_id'], $_POST['bname'], $_POST['bdesc'], $_POST['article_id'],  $_POST['price']);
      $done = $stmt->execute();
      }
  }
// redirect on success or if $_GET array empty and form not submitted
if ($done || (!$_GET && !$_POST)) {
  header('Location: journal_list_fmt_mysqli.php');
  exit;
  }
// display error message if query fails
if (isset($stmt) && !$OK && !$done) {
  echo $stmt->error;
  }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Journal - update record</title>
<link href="../assets/admin.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
#Layer1 {
      position:absolute;
      width:625px;
      height:700px;
      z-index:1;
      left: 8px;
      top: 5px;
      padding: 10px;
      background-color: #999999;
      border: medium solid;
      border-color: #000099;
}
body {
      background-color: #F6C38E;
}
a:link {
      color: #000099;
}
a:visited {
      color: #000099;
}
a:hover {
      color: #F6C38E;
}
a:active {
      color: #F6C38E;
}
#Layer2 {
      position:absolute;
      left:21px;
      top:16px;
      width:93px;
      height:36px;
      z-index:2;
      background-color: #000099;
}
body,td,th {
      font-family: Gill Sans MT, Tahoma;
}
.style2 {
      font-size: 24px;
      color: #F6C38E;
      font-family: "Gill Sans MT", Tahoma;
      font-weight: bold;
}
-->
</style>
</head>

<body><div id="Layer1"><div class="style2" id="Layer2">ADMIN</div>
<h1 align="center">EDIT Bulb List </h1>
<p align="center"><a href="journal_list_fmt_mysqli.php">List all entries </a>&nbsp;&nbsp;<a href="catalogue.php">View Customer Catalogue </a></p>
<?php if($article_id == 0) { ?>
<p class="warning">Invalid request: record does not exist.</p>
<?php }
else {
?>
<form id="form1" name="form1" method="post" action="">
    <p><div align="center">
        <label for="bname">BULB NAME:</label>
        <input name="bname" type="text" class="widebox" id="title" value="<?php echo htmlentities($bname); ?>" size="80" /></div>
    </p> <p><div align="center">
        <label for="article_id">BULB NAME:</label>
        <input name="article_id" type="text" class="widebox" id="title" value="<?php echo htmlentities($article_id); ?>" size="20" /></div>
    </p>
      <p>
    <div align="center"><label for="price">PRICE:</label>
        <input name="price" type="text" class="widebox" id="title" value="<?php echo htmlentities($price); ?>" />
   </div> </p>
    <p>    </p>
      
      <p><div align="center">
        <label for="bdesc">DESCRIPTION:</label>
        <textarea name="bdesc" cols="60" rows="8" class="widebox" id="bdesc"><?php echo htmlentities($bdesc); ?></textarea></div>
  </p>
       <div align="center">
      <label for="image_id">
     Image:      </label>
     
        <select name="image_id" id="image_id">
          <option value="">Select image</option>
          <?php
            while ($image = $imageList->fetch_assoc()) {
            ?>
          <option value="<?php echo $image['image_id']; ?>"
            <?php
            if ($image['image_id'] == $image_id) {
              echo ' selected="selected"';
              }
            ?>><?php echo $image['filename']; ?>            </option>
          <?php } ?>
        </select>  
    </div>
      </p>
    <p><div align="center">
        <input type="submit" name="update" value="Update entry" />
            <input name="article_id" type="hidden" value="<?php echo $article_id; ?>" /></div>
    </p>
</form>
<?php } ?></div>

</body>
</html>
LeighJorAsked:
Who is Participating?
 
babuno5Connect With a Mentor Commented:
i cant make out any errors but you  can try the following so that if there are any errors php will point out the same

<?php
error_reporting(1);
include('corefuncs.php');
// remove backslashes
nukeMagicQuotes();
// initialize flags
$OK = false;
$done = false;
 // create database connection
$conn = new mysqli('localhost','dodgy', 'dodgy1', 'dodgy2' ) or die ( 'cannot opendb');
.
.
.
.
0
 
nizsmoConnect With a Mentor DeveloperCommented:
Where and what exactly does your edit form fail to work? Or what is it suppose to do that it isn't doing?
0
 
LeighJorAuthor Commented:
Its not happening -- the database is not being upadted. It whistles along pretending to do the job but doesnt do a thing.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
LeighJorAuthor Commented:
I can insert new records through similiar form but cannot get the edit form above to work
0
 
siva_sivaConnect With a Mentor Commented:
You will change the if condition and try again,

// if form has been submitted, update record
if (isset($_POST['update'])) {
      $sql = 'UPDATE journal SET image_id = ?, bname = ?, bdesc = ?, price = ? WHERE article_id = ?';
      $stmt = $conn->stmt_init();
      if ($stmt->prepare($sql)) {
            $stmt->bind_param('issis', $_POST['image_id'], $_POST['bname'], $_POST['bdesc'], $_POST['article_id'],  $_POST['price']);
            $done = $stmt->execute();
      }
}
0
 
LeighJorAuthor Commented:
Eureka I found it:  
 $sql = 'UPDATE journal SET image_id = ?, bname = ?, bdesc = ?, price = ? WHERE article_id = ?';
  $stmt = $conn->stmt_init();
  if ($stmt->prepare($sql)) {
    $stmt->bind_param('issis', $_POST['image_id'], $_POST['bname'], $_POST['bdesc'], $_POST['article_id'],  $_POST['price']);
The input from the post was not  amtching the sql. When I transposed ---$_POST['article_id'],  $_POST['price'] --- it worked
Thanks all

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.