Results 1 to 11 of 11

Thread: showing image as part of a record

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    62

    showing image as part of a record

    hiya I'm a bit stuck here.

    I wrote a form so people could enter information for a bio, added the db table and it all works perfectly.

    Person enters thier info, hit's send, info is stored in the db and a result is returned back to the user.

    What I'm having issues with is createing a page where they enter in thier unique ID (which is also the primary key) and it returns the bio information.

    3 of the fields are images and the user enters the url for the image which is also stored in the db but none of the images will show...even on a test page. Can someone quide me with proper code for showing an image as part of a profile?

    Ex :

    UID : 1
    Name : Bob
    Avatar : http://bobs.com/bob.gif

    All three of those fields are in the db and are named the same and use the same format.

    "If at first you don't succeed, destroy all evidence you ever tried."
    http://www.ussretribution.com

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: showing image as part of a record

    this should work fine:
    PHP Code:
    <?php
      $sql 
    "SELECT uid, name, avatar FROM tablename WHERE uid='1'";
      
    $query mysql_query($sql);
      
    $arr mysql_fetch_assoc($query);
      
    //debugging purposes
      
    echo '<pre>';
      
    print_r($arr);
      echo 
    '</pre>';
    ?>
    <img src="<?php echo $arr['avatar']; ?>" alt="<?php echo $arr['name']; ?>" />
    you should post some of your code to show us what you're doing first, that way we can make sure you're doing things correctly.

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    62

    Re: showing image as part of a record

    Ok, here's the code I'm using, with all the tables : The last field is the image (but there will be others)

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>AlphaFleet - Database Modifier Tool</title>
    <link type="text/css" rel="stylesheet" href="af.css">
    </head>
    <body>
    <?php
    $db_name = "afbios";
    $table_name = "bios";
    $connection = @mysql_connect("localhost", "bob", "bobspwd")
    	or die(mysql_error());
    $db = @mysql_select_db($db_name, $connection) or die(mysqlerror());
    $sql = "INSERT INTO $table_name (uid, cgender, cname, cheight, cage, cweight, cspecies, ceye, chair, cmarried, crank, cpos, cmarks, cfam, cedu, csr, cbg, can, ckl, ceu, cac, cav) VALUES ('$_POST[uid]', '$_POST[cgender]', '$_POST[cname]', '$_POST[cheight]', '$_POST[cage]', '$_POST[cweight]', '$_POST[cspecies]', '$_POST[ceye]', '$_POST[chair]', '$_POST[cmarried]', '$_POST[crank]', '$_POST[cpos]', '$_POST[cmarks]', '$_POST[cfam]', '$_POST[cedu]', '$_POST[csr]', '$_POST[cbg]', '$_POST[can]', '$_POST[ckl]', '$_POST[ceu]', '$_POST[cac]', '$_POST[cav]')";
    $result = @mysql_query($sql,$connection) or die(mysql_error());
    ?>
    <h1>Adding a bio to <?php echo "$table_name"; ?></h1>
    <table width="100%"  cellspacing=3 cellpadding=3 border="1">
      <tr>
    	<td width="50%" valign=top><div align="center"><strong>User ID ::</strong><br>
    <?php echo "$_POST[uid]"; ?></p></div></td>
        <td width="50%"><div align="center"><strong>Gender ::</strong><br>
    <?php echo "$_POST[cgender]"; ?></div></p></td>
      </tr>
      <tr>
        <td width="50%"><div align="center"><p><strong>Character Name ::</strong><br>
    <?php echo "$_POST[cname]"; ?></p></div></td>
        <td width="50%"><div align="center"><p><strong>Height ::</strong><br>
    <?php echo "$_POST[cheight]"; ?></p></div></td>
      </tr>
      <tr>
        <td width="50%"><div align="center"><p><strong>Age ::</strong><br>
    <?php echo "$_POST[cage]"; ?></p></div></td>
        <td width="50%"><div align="center"><p><strong>Weight (lbs) ::</strong><br>
    <?php echo "$_POST[cweight]"; ?></p></div></td>
      </tr>
      <tr>
        <td width="50%"><div align="center"><p><strong>Species ::</strong><br>
    <?php echo "$_POST[cspecies]"; ?></p></div></td>
        <td width="50%"><div align="center"><p><strong>Eye Color ::</strong><br>
    <?php echo "$_POST[ceye]"; ?></p></div></td>
      </tr>
      <tr>
        <td width="50%"><div align="center"><p><strong>Hair Color ::</strong><br>
    <?php echo "$_POST[chair]"; ?></p></div></td>
        <td width="50%"><div align="center"><p><strong>Marital Status ::</strong><br>
    <?php echo "$_POST[cmarried]"; ?></p></div></td>
      </tr>
      <tr>
        <td width="50%"><div align="center"><p><strong>Rank ::</strong><br>
    <?php echo "$_POST[crank]"; ?></p></div></td>
        <td width="50%"><div align="center"><p><strong>Position ::</strong><br>
    <?php echo "$_POST[cpos]"; ?></p></div></td>
      </tr>
      <tr>
        <td width="50%"><div align="center"><p><strong>Distinguishing Features ::</strong><br>
    <?php echo "$_POST[cmarks]"; ?></p></div></td>
        <td width="50%"><div align="center"><p><strong>Family ::</strong><br>
    <?php echo "$_POST[cfam]"; ?></p></div></td>
      </tr>
      <tr>
        <td width="50%"><div align="center"><p><strong>Education ::</strong><br>
    <?php echo "$_POST[cedu]"; ?></p></div></td>
        <td width="50%"><div align="center"><p><strong>Service Record ::</strong><br>
    <?php echo "$_POST[csr]"; ?></p></div></td>
      </tr>
      <tr>
        <td width="50%"><div align="center"><p><strong>Background History ::</strong><br>
    <?php echo "$_POST[cbg]"; ?></p></div></td>
        <td width="50%"><div align="center"><p><strong>Additional Notes ::</strong><br>
    <?php echo "$_POST[can]"; ?></p></div></td>
      </tr>
      <tr>
        <td width="50%"><div align="center"><p><strong>Known Languages ::</strong><br>
    <?php echo "$_POST[ckl]"; ?></p></div></td>
        <td width="50%"><div align="center"><p><strong>Equipment Used ::</strong><br>
    <?php echo "$_POST[ceu]"; ?></p></div></td>
      </tr>
      <tr>
        <td width="50%"><div align="center"><p><strong>Awards & Commendations ::</strong><br>
    <?php echo "$_POST[cac]"; ?></p></div></td>
        <td width="50%"><div align="center"><p><strong>Avatar ::</strong><br>
    <?php echo "$_POST[cav]"; ?></p></div></td>
      </tr>
    </table>
    <p><a href="Bioenter.htm">Add Another?</a></p>
    </body>
    </html>

    "If at first you don't succeed, destroy all evidence you ever tried."
    http://www.ussretribution.com

  4. #4
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: showing image as part of a record

    okay, well, first of all, when you're posting code, please try to only post the relevant parts. no one really wants to read through a long page of code, where only a couple of lines actually relate to the question at hand. now, aside from that... some advice: when you're echoing variables, it's much easier to use (echo $_POST['varname'];) instead of (echo "$_POST[varname]";).

    and finally, to solve your real issue, are you not familiar with HTML..? if you want to display an image, you need to use the <img> HTML tag, you can't just display the link to the image. like so:
    PHP Code:
        <td width="50%" align="center"><strong>Avatar ::</strong><br />
    <img src="<?php echo $_POST['cav']; ?>" /></td>
    and another tip: if you're not actually using your <div> elements for anything but centering, you should apply the "align" attribute to the table cell (<td>) instead. This will save a lot of text, and makes thing a bit more tidy. I would also not bother using a paragraph tag, but it all depends on what's going to be in your table's cells.
    Code:
    <td width="50%" align="center"><strong>Character Name ::</strong><br />
    <?php echo $_POST['cname']; ?></td>

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    62

    Re: showing image as part of a record

    ah, ok. I'm a dreamweaver slave and mostly does what it tell me, mainly because unless I want something specific, it produces what I need.

    I'll keep in mind about the displaying code too. I only posted the full page because I'm about as close to a rook with php as you can get and wanted to show exactly what I was working with.

    "If at first you don't succeed, destroy all evidence you ever tried."
    http://www.ussretribution.com

  6. #6

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    62

    Re: showing image as part of a record

    Little note : I can't believe Imissed what was so obvious. I've bought books, surfed the net, stayed up til 3 AM looking for the answer but didn't think to check the obvious. I can port databases, fix DB code....but didnt think to see if the program was being told the right stuff.


    tytytytytyytyttyty (is all I can say)

    "If at first you don't succeed, destroy all evidence you ever tried."
    http://www.ussretribution.com

  7. #7
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: showing image as part of a record

    Don't use tables for layout.

    Learn HTML and CSS and get rid of Dreamweaver.

  8. #8
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: showing image as part of a record

    If your a website templater, i'd keep dreamweaver, but try and not rely on what it automatically generates.

    Just a simple notepad + FTP Client works wonders...lol. Abeit it can produce sloppy code, if you 'dont' pay attention.
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  9. #9

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    62

    Re: showing image as part of a record

    I did the manual write for both the form and the script using css, both of which worked remarkably well.

    I started out writing it in frontpage, because is doesn't auto insert endtags (serious painin my butt). ended up finishing it in dreamweaver though....I wanted to quickly identify php tags.

    Onto a whole new ballgame now though....working on writing a script where I select an individual's name who has entered a bio, and a new page is generated, showing thier record. Still pluggin but it's taking time. I'll post alink when I'm done so you guys can see what you helped me create. (I'mm a simming junkie and wanted something unique...not canned like everyone else has)

    "If at first you don't succeed, destroy all evidence you ever tried."
    http://www.ussretribution.com

  10. #10

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    62

    Re: showing image as part of a record

    Heya again. Spent the whole moring coding my little project but came to one part that's seconds away from driving me to drink and I'm not certain how to get past it...

    Here's the code :

    PHP Code:
    11    $db = @mysql_select_db($db_name$connection)
    12        or die(mysql_error());
    13    $sql "SELECT uid, cname FROM $table_name ORDER BY uid";
    14    $result = @mysql_query($sql,$connection) or die(mysql_error());
    15    $num $mysql_num_rows($result); 
    I put in row numbers because the error I get specifies a row number.

    Here's the error : Fatal error: Call to undefined function: () in /home/ussretri/public_html/AGM/edit_record.php on line 15

    I've gone through the code but can't see where the error is, even chance the field name but that just tells me that yes, the connection is working (got a desired error...no field name found). Any thoughts?
    Last edited by Albatross; Dec 17th, 2006 at 11:49 AM.

    "If at first you don't succeed, destroy all evidence you ever tried."
    http://www.ussretribution.com

  11. #11
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: showing image as part of a record

    you're calling $mysql_num_rows() instead of mysql_num_rows(). Because you're referencing a variable ($mysql_num_rows), PHP is looking for the function that is the value of the variable. So.. since the variable $mysql_num_rows isn't actually defined, it is coming up blank. Remove the dollar sign and everything will work fine for you. I do that sometimes too, I would have to say it would be a fairly common mistake.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width