Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: code adds my url to url for link?

  1. #1
    Join Date
    Apr 2010
    Location
    University of Illinois
    Posts
    86
    Thanks
    13
    Thanked 2 Times in 2 Posts

    Default code adds my url to url for link?

    Code:
    <?php
    // Retrieve all the data from the "webcalendar_events" table
    $result = mysql_query("SELECT * FROM webcalendar_events )
    or die(mysql_error());  
    
     echo 
     "Decription: {$row['description']}</p>";
    }
    I got a calendar from PHPScripts which allows you to enter links in it.
    The above script (I snipped) is used to get featured dates to place on the page. Works great, with the help of Traq, but for some reason my webpage added my url to links found in the description field. If the link in the calendar (which works correctly within the calendar) is
    Code:
    http://www.there.com
    the link I get using the above code gives me a link with the address
    Code:
    http://mysite.com/%22http://www.there.com
    Is the problem the script? or the way the calendar puts it into the db?

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    It's impossible to know why that is happening from the information you posted.
    The first thing to do is check how it is stored in the database. Do you have phpmyadmin or another way to view it directly? If not, I'd recommend doing a much simpler query that just prints out all the data so you can look at it:
    PHP Code:
    <?php
    //run this as a new page
    //then click view>source
    /////
    //connect to the database!!
    /////
    $q mysql_query('SELECT * FROM `mytable`;');
    while(
    $r mysql_fetch_assoc($q)) {
    print_r($r);
    }
    ?>
    It may very well be how the calendar saves it, but we can't know that yet.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Apr 2010
    Location
    University of Illinois
    Posts
    86
    Thanks
    13
    Thanked 2 Times in 2 Posts

    Default

    Your script gave me an array...the same thing I was getting with the field names.

    I looked at the fields in the database and the urls are stored like this

    Code:
    <a href=\"http://page.com\">link</a>

  4. #4
    Join Date
    Apr 2010
    Location
    University of Illinois
    Posts
    86
    Thanks
    13
    Thanked 2 Times in 2 Posts

    Default

    Array ( [id] => 4 [calendar_id] => 1 [dt] => 2010-08-20 [color] => ffff00 [description] => test of events to be printed on page. tiis is iit KCM )

    The above is what I get from the script you gave me. KCM was a link...the link is gone now but the url was my site and the link seperated by %22

    I cut all but one record to make it more readable.
    Last edited by I am Abby; 08-18-2010 at 07:37 PM.

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    As I said, view it as source code, not as HTML.
    The text output in the source code is what you are dealing with.
    After that, it should be easy to figure out.
    And yes, it will be an array. That is to view this if you do NOT have another way to view it directly. If you have phpmyadmin or another option like that, you should just view it that way.

    This is all just to see what format it is stored in and whether it is even possible to do what you are attempting. Once you know that, then you can determine the next step.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #6
    Join Date
    Apr 2010
    Location
    University of Illinois
    Posts
    86
    Thanks
    13
    Thanked 2 Times in 2 Posts

    Default

    Not sure what do you mean "view it as source code"

    When I look into the database at the record, the description field has "Another item to test <a href=\"http://uiuc.edu\">U of I</a>" in it.

    when I run that code you gave me above...I get a list of everything in the array but the field looks like "Another item to test U of I"
    Last edited by I am Abby; 08-19-2010 at 08:43 PM.

  7. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    "view as source" means viewing the HTML code as text, after it is generated by PHP. The easiest way to do that is to create a page on your server, save it, then go to the URL and click "edit>view source" (or whatever method works in your browser).
    That was only to be able to view exactly what was being generated from your database. But since you found another way to view it, that is no longer important.

    If you have the text stored containing HTML directly (such as the links) it will be a lot harder to modify than if it was stored separately. I'm not sure what to suggest aside from some complex form of search and replace operation.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #8
    Join Date
    Apr 2010
    Location
    University of Illinois
    Posts
    86
    Thanks
    13
    Thanked 2 Times in 2 Posts

    Default

    Wow, I was sick, sick, sick this weekend but I'm better now...don't you just hate getting sick on the weekend!

    The source code looks like this...doesn't this look right?

    Code:
    <body>
    <p><strong>August 20, 2010</strong><br />Decription: test of events to be printed on page.
     
    this is it <a href=\"http://www.uiuc.edu\">U of I</a></p><p><strong>September 14, 2010</strong></p>
    But when you move the mouse over the link on the page it looks like
    Code:
    http://mysite.com/%22http://www.there.com

  9. #9
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Interesting. Is there a base href on the page?
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  10. #10
    Join Date
    Apr 2010
    Location
    University of Illinois
    Posts
    86
    Thanks
    13
    Thanked 2 Times in 2 Posts

    Default

    Here is the complete code for the test page. Only thing I changed was the mysql_connect information...

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    <body>
    <?php
    // Make a MySQL Connection
    mysql_connect("xxx.xxx.xxx.xx", "login", "password") or die(mysql_error());
    mysql_select_db("nlchdb") or die(mysql_error());
    
    // Retrieve all the data from the "webcalendar_events" table
    $result = mysql_query("SELECT * FROM webcalendar_events WHERE dt >= now() AND color='ffff00' ORDER BY dt")
    or die(mysql_error());  
    
    while($row = mysql_fetch_array($result, MYSQL_ASSOC))
    {
    $monthnames = array(
    "01"=>"January",
    "02"=>"February",
    "03"=>"March",
    "04"=>"April",
    "05"=>"May",
    "06"=>"June",
    "07"=>"July",
    "08"=>"August",
    "09"=>"September",
    "10"=>"October",
    "11"=>"November",
    "12"=>"December");
    
     list($year, $month, $day) = split('[/.-]', $row['dt']);
     $month = $monthnames[$month];
     echo "<p><strong>{$month} {$day}, {$year}</strong><br />".
     "Decription: {$row['description']}</p>";
    }
    $q = mysql_query("SELECT * FROM webcalendar_events WHERE dt >= now() AND color='ffff00' ORDER BY dt");
    while($r = mysql_fetch_assoc($q)) {
    print_r($r);
    }
    ?>
    
    </body>
    </html>
    Again the code does a good job with the exception of adding extra info to the link urls.

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
  •