Guys, there's a problem lies on my code...cant display the image in viewing candidates..i already put the code <img src=\"".$row['image']."\"> as what my friend here said in my code in viewing but it seems it didn't work out..
here's my adding record..

add_new.php

<?php

      /*

        NEW.PHP
 
        Allows user to create a new entry in the database

      */

      // creates the new record form

      // since this form is used multiple times in this file, I have made it a function that is easily reusable
  
      function renderForm($name, $position, $partyname, $error)
  
      {

      ?>
 
       

      <?php

      // if there are any errors, display them
  
      if ($error != '')
  
      {
 
      echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
 
      }
 
      ?>
  
      <form action="" enctype=multipart/form-data method="post">

      <center><table width="50%" cellspacing="0" cellpadding="4" border="0">

      <tr> <td width="40%">First Name:</td><td width="80%"><input type="text" name="f_name"/></td></tr><br>

      <tr> <td width="40%">Last Name:</td><td width="80%"><input type="text" name="l_name"/></td></tr><br>

      <tr> <td width="40%">Middle Name:</td><td width="80%"><input type="text" name="m_name"/></td></tr><br>
 
      <tr><td width="40%">Position:</td><br>
  
      <?php

      include('connect-db.php');

      $result = mysql_query("SELECT * FROM positions")

      or die(mysql_error());

      echo"<td width=80%><select name=position>";
 
      while($row = mysql_fetch_array( $result )) {
  
      echo '<option value="'.$row['position'].'">' . $row['position'] . '</option>';
  
      }
 
      echo "</select></td></tr>";
  
      ?>
 
      <tr><td width="40%">Party Name:</td>

      <?php

      include('connect-db.php');

       
 
      $result = mysql_query("SELECT * FROM partynames")

      or die(mysql_error());

      echo"<td width=80%><select name=partyname>";

      while($row = mysql_fetch_array( $result )) {
 
      echo '<option value="'.$row['partyname'].'">' . $row['partyname'] . '</option>';

      }

      echo "</select></td></tr>";

       

      ?>

      <input type=hidden name=MAX_FILE_SIZE value=150000>
 
      <input type=hidden name=completed value=1>
  
      Please choose an image to upload: <input type=file name=imagefile><br>

      Please enter the title of that picture: <input name=whatsit><br>

      </form>
 
      <tr><td></td><td></td></tr>

      <tr><td></td><td align="left"><input type="submit" name="submit" value="Add"></td></tr>
 
      </table>

      </form>

      <?php
 
      }

      // connect to the database
 
      include('connect-db.php');

       
  
      // check if the form has been submitted. If it has, start to process the form and save it to the database

      if (isset($_POST['submit']))

      {

      // get form data, making sure it is valid

      $f_name = htmlspecialchars($_POST['f_name']);

      $l_name = htmlspecialchars($_POST['l_name']);

      $title = htmlspecialchars($_POST['title']);

      $imgdata = htmlspecialchars($_POST['imgdata']);

      $m_name = htmlspecialchars($_POST['m_name']);

      $position = htmlspecialchars($_POST['position']);

      $partyname = htmlspecialchars($_POST['partyname']);


      // check to make sure both fields are entered

      if (f_name == '' || l_name == '' || title == '' || imgdata == '' || m_name == '' || position == '' || partyname == '')

      {

      // generate error message

      $error = 'ERROR: Please fill in all required fields!';
 
      // if either field is blank, display the form again

      renderForm($id,$f_name, $l_name, $title, $imgdata, $m_name, $position, $partyname, $error);
 
      }

      else

      {

      // save the data to the database

      mysql_query("INSERT candidates SET f_name='$f_name', l_name='$l_name', title='$title', imgdata='$imgdata', m_name='$m_name', position='$position', partyname='$partyname'")

      or die(mysql_error());

      echo"<br><br><center>Succesfully added!";

      }

      }

      else

      // if the form hasn't been submitted, display the form

      {

      renderForm('','','','','','','','');

      }

      if ($_REQUEST[completed] == 1) {

      // Need to add - check for large upload. Otherwise the code

      // will just duplicate old file ;-)

      // ALSO - note that latest.img must be public write and in a

      // live appliaction should be in another (safe!) directory.

      move_uploaded_file($_FILES['imagefile']['tmp_name'],"latest.img");

      $instr = fopen("latest.img","rb");

      $image = addslashes(fread($instr,filesize("latest.img")));

      if (strlen($instr) < 149000) {

      mysql_query ("insert into candidates (title, imgdata) values (\"".

      $_REQUEST[whatsit].

      "\", \"".

      $image.

      "\")");

      } else {

      $errmsg = "Too large!";

      }

      }
 
      // If this is the image request, send out the image

      if ($_REQUEST[gim] == 1) {

      header("Content-type: image/jpeg");

      print $bytes;

      exit ();

      }

      ?>

view_records.php

<?php
  
      include('connect-db.php');

 
      $result = mysql_query("SELECT * FROM candidates")

      or die(mysql_error());

      echo "<table width='600' cellspacing='0' cellpadding='0' border='1' align='center'>";

      echo "<tr> <th bgcolor='lightblue'>Picture</th><th bgcolor='lightblue'>FirstName</th><th bgcolor='lightblue'>LastName</th><th bgcolor='lightblue'>MiddleName</th><th bgcolor='lightblue'>Position</th> <th bgcolor='lightblue'>PartyName</th> <th bgcolor='lightblue'>Action</th></tr>";

      // loop through results of database query, displaying them in the table
 
      while($row = mysql_fetch_array( $result )) {

      // echo out the contents of each row into a table

      echo '<td><center><img src=\''.$row['imgdata'] .\''> '</td>';

      echo '<td><center>' . $row['f_name'] . '</td>';

      echo '<td><center>' . $row['l_name'] . '</td>';

      echo '<td><center>' . $row['m_name'] . '</td>';

      echo '<td><center>' . $row['position'] . '</td>';

      echo '<td><center>' . $row['partyname'] . '</td>';

      echo '<td><center><a href="edit_candidates.php?id=' . $row['id'] . '">Modify</a>&nbsp;&nbsp;&nbsp;<a href="delete_candidates.php?id=' . $row['id'] . '">Delete</td>';

      echo "</tr>";

      }
 
      echo "</table>";

      ?>

Pls find out whats the problem lies about. i need to implement it..tnx..

here's the error in my program..

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in C:\wamp\www\41e1\candidate\view_records.php on line 121

>cant display the image in viewing candidates

...
 echo "<td><center><img src=\"$row[imgdata]\"></td>";
 ...

ok i'll try this..and if it is not work,can you pls if you dont mind to have a link with the image.?someone says that it is better to use to put a link of the image in a table and when you click the link,the image of that user will display..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.