SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2005
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with PHP and an HTML Form

    I've built a small CMS for a client where they can update information on a page. Everything works fine, except for one problem. One of the fields they can update is a link. The first time the information is entered (such as <a href="http://www.gigantic.com/gigantic/default.aspx" target="_blank">GIGANTIC</a>) everything is good and the info is entered into the MySQL database properly and shows up on the web page properly. The problem lies when they go to edit this information. It seems that when the info is pulled out of the database to display on the Admin page for them to edit there is a problem displaying the link inside of the VALUE field for this item. In the code it looks like it should (value="<a href="http://www.gigantic.com/gigantic/default.aspx" target="_blank">GIGANTIC</a>" />. BUT, the HTML apparently assumes the " after <a href= is the end of the VALUE filed and the rest of the information is not included in the field for editing. So I need to figure out to how put the code for a link into a VALUE field to avoid this. I hope this make sense. Any suggestions or help would be greatly appreciated. Thank you very much.

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    what's your code to display it?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2005
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The code on the Admin page to display it is:
    <p class="by">Tickets/p>
    <div class="searchdivsingle"><input type="text" name="ticketedit" value="<?php echo $tickets; ?>" /></div>
    So, it pulls the value of $tickets from the MySQL database. That all works as it should. BUT, when that value is put into the VALUE field it results in this:
    <p class="by">Tickets/p>
    <div class="searchdivsingle"><input class="tickets" name="ticketsedit" type="text" value="<a href="http://www.gigantic.com/gigantic/default.aspx" target="_blank">GIGANTIC</a>" />
    </div>
    And like I say, the HTML reads the " after <a href as the end of the value field. So on the Admin page, only <a href shows up in the field to edit.

  4. #4
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    please use [ php ] tags to put code in.

    What you need to do is change the value tags to be sing-quoted, e.g.
    PHP Code:
    <p class="by">Tickets:</p>
    <div class="searchdivsingle"><input type="text" name="ticketedit" value='<?php echo $tickets?>' /></div>
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  5. #5
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Or, another alternative is to put the input in a textarea:
    PHP Code:
    <p class="by">Tickets: </p>
    <div class="searchdivsingle"><textarea name="ticketedit"><?php echo $tickets?></textarea></div>
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  6. #6
    SitePoint Enthusiast
    Join Date
    Jul 2005
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the suggestions. As for the first one, I see two problems: 1. If you put a variable inside single quotes the PHP will not read the variable as a variable, but simply as text, right? and 2. the problem is not pulling the information from the database, it's being pulled and displayed correctly. It's simply that the value field doesn't work when it is displayed correctly.

    The second suggestion makes sense and I will give that a try.

    Thanks again.

  7. #7
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    also, you may want to look at htmlspecialchars.
    PHP Code:
    <p class="by">Tickets:</p> <div class="searchdivsingle"><input type="text" name="ticketedit" value="<?php echo htmlspecialchars($ticketsENT_QUOTES); ?>" /></div>
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  8. #8
    SitePoint Enthusiast
    Join Date
    Jul 2005
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, thanks, I'll take a look at that as well.


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
  •