SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Code error on alt tag - help please

    Hi
    Sorry to post what may be a numpty question. I can usually work things out but this has got me stuck. Can't seem to find an answer I understand through Google either :-(

    I'm jst trying to learn PHP and really struggling. I have a MYSQL database with fields for specifications and now want to add an image. I've got it in a table appearing in the correct page and managed to get an alt tag and title picked up from the name and model fields. It's all fine, but the validation is suggesting I've got quote marks wrong? I don't yet understand why you would use " or ' but be substituting one for the other I've managed to get the image to appear and the properties correct. I now want it valid to XHTML

    so here's the code
    <td align='right'><img src=" . $image ." alt='$name $model' title='$name $model' /> <br /></td></tr></table>

    and here's the error

    Line 41, Column 31: an attribute value specification must be an attribute value literal unless SHORTTAG YES is specified.

    <td align='right'><img src= alt='Bronica Zenzanon-EII 500mm f/8' title='Broni


    Hope you guys can and will point me in the right direction

    Edit Oh hang on I've added ' around img src and it now works...didn't need to post after all...unless you have a better way of doing what I've done?

    <td align='right'><img src='" . $image ."' alt='$name $model' title='$name $model' /> <br /></td></tr></table>
    Last edited by EPZPETE; Jul 18, 2008 at 06:56. Reason: found part of answer

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Hi and welcome to the forums

    at the minute you have something like:
    PHP Code:
    echo "<td align='right'><img src=" $image ." alt='$name $model' title='$name $model' /> <br /></td></tr></table>"
    To keep the HTML correctly formed you should use single quotes for the string as follows:
    PHP Code:
    echo '<td align="right"><img src="'$image '" alt="'$name .  $model .'" title="'$name .  $model .'" /> <br /></td></tr></table>'
    so you can maintain the HTML code properly.

    Also check that the $image variable is appearing correctly as I dont think it is showing up.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks Spike for a quick reply and the kind welcome...I had to change " to ' so it worked as the php variables are using "" Was this correct?

    Here's a sample of my php earlier on the page which causes problems if I have double quotes on img src etc

    //the format is $variable = $r["nameofmysqlcolumn"];
    //modify these to match your mysql table columns

    $angle=$r["angle_of_view"];
    $name=$r["name"];
    $model=$r["model"];
    ....

  4. #4
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    now they are array values and can happily be put into single quotes. I generally if not always single quote array values.

    PHP Code:
    $angle=$r['angle_of_view'];
    $name=$r['name'];
    $model=$r['model']; 
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  5. #5
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Brilliant, thanks Spike, that's the trick...just 15 errors to go.. which is better than the 122 I previously had!

  6. #6
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Then we are on the right road
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....


Bookmarks

Posting Permissions

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