user3626062
user3626062

Reputation: 25

Display record in form in php

Hello everyone i would like to display certain information that i have fetch from my database in MySQL in PHP, the problem is that nothing is being displayed into the form can someone help to solve this issue please?

<?php
  require 'db2.php';
  $id = null;
  if ( !empty($_GET['id'])) {
    $id = $_REQUEST['id'];
  }
  if ( null==$id ) {
    header("Location: index.php");
  } else {
    $dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not   connect to MySQL: ' . mysqli_connect_error() );
    $q = mysqli_query($dbc,"SELECT * FROM movie WHERE MovieID = '$id' ");
    while($r=mysqli_fetch_array($q))
    {   
      $title = $r["Title"];
      $tag = $r["Tag"];
      $Year = $r["YEAR"];
      $Cast = $r["Cast"];
    }
  }
?>

the form is below :

<div class="span10 offset1">
  <div class="row">
    <h3>Movie Information</h3>
  </div>

  <div class="form-horizontal" >
    <div class="control-group">
      <label class="control-label">Title</label>
      <div class="controls">
        <label class="checkbox">
          <?php echo $r['Title'];?>
        </label>
      </div>
    </div>
    <div class="control-group">
      <label class="control-label">Year</label>
      <div class="controls">
        <label class="checkbox">
          <?php echo $r['email'];?>
        </label>
      </div>
    </div>
    <div class="control-group">
      <label class="control-label">Cast</label>
      <div class="controls">
        <label class="checkbox">
          <?php echo $r['mobile'];?>
        </label>
      </div>
    </div>
    <div class="control-group">
      <label class="control-label">Tags</label>
      <div class="controls">
        <label class="checkbox">
          <?php echo $r['mobile'];?>
        </label>
      </div>
      <div class="control-group">
        <label class="control-label">Image</label>
        <div class="controls">
        <label class="checkbox">
          <?php echo $r['mobile'];?>
        </label>
      </div>
    </div>
    <div class="form-actions">
      <a class="btn" href="index.php">Back</a>
      &nbsp; &nbsp;
      <a class="btn" href="index.php">Update</a>
    </div>
  </div>
</div>

Upvotes: 1

Views: 102

Answers (1)

Funk Forty Niner
Funk Forty Niner

Reputation: 74220

You need to use <?php echo $title;?> instead of <?php echo $r['Title'];?>
since you're already assigning it in $title = $r["Title"]; etc.

Change that and do the same for the others.

Upvotes: 2

Related Questions