[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

PHP Very Very Urgent edit form will not work

Posted on 2007-10-07
6
Medium Priority
?
282 Views
Last Modified: 2013-12-13
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>
0
Comment
Question by:LeighJor
6 Comments
 
LVL 15

Accepted Solution

by:
babuno5 earned 600 total points
ID: 20032457
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
 
LVL 21

Assisted Solution

by:nizsmo
nizsmo earned 300 total points
ID: 20032478
Where and what exactly does your edit form fail to work? Or what is it suppose to do that it isn't doing?
0
 

Author Comment

by:LeighJor
ID: 20032700
Its not happening -- the database is not being upadted. It whistles along pretending to do the job but doesnt do a thing.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:LeighJor
ID: 20032703
I can insert new records through similiar form but cannot get the edit form above to work
0
 
LVL 5

Assisted Solution

by:siva_siva
siva_siva earned 600 total points
ID: 20032893
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
 

Author Comment

by:LeighJor
ID: 20038133
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question