spiotr12
spiotr12

Reputation: 79

Some html tags' parameters messup html/php code

When I create/edit post to my website, and when I use html tags (either type it by my self or using WYSIWYG editor (in this case nicEdit, but I've used different one - same problem)) it does not show anything on the page.

to be more specific: I have article container which imports php code, which than iterates through the db table and echo posts. This is the code:

<h3>Wydarzenia</h3>
<?php
    //collects data from table "events" and sort it by "id" date in descending oreder
    $event_table_data = mysqli_query($db_con, "SELECT * FROM events ORDER BY id DESC") 
        or die(mysqli_error());

    //puts the data from "events" into an array
    $event_content_array = mysqli_fetch_array($event_table_data); 

    //makes variables from table columns
    $id = id;
    $title = title;
    $happeninng_date = happen;
    $created_date = created;
    $content = content;
    $author = author;

    //add new post button
    if((isset($_SESSION['sess_wizardrights'])) && ($_SESSION['sess_wizardrights'] == true)){
        echo    "<a class='e_event_addpost_link' href='./index.php?link=add_post'><button  class='e_event_addpost_button' type='button'>Dodaj nowy post</button></a>";
    }

    do{
        //echo each event for main event article
        echo    "<span class='b_events_span' id='" . $event_content_array[$id] . "'>";
        echo    "   <a class='b_events_anchor' id='" . $event_content_array[$id] . "'></a>";
        echo    "   <h2 class='b_events_title'>" . $event_content_array[$title] . "</h2>";
        if((isset($_SESSION['sess_wizardrights'])) && ($_SESSION['sess_wizardrights'] == true)){
            echo    "<form class='b_events_edit_form' name='edit_post' action='./index.php?link=edit_post' method='post'>";
            echo    "   <input type='hidden' name='id' value='" . $event_content_array[$id] . "'> ";
            echo    "   <input class='e_events_edit_submit' type='submit' value='Edytuj wydarzenie'>";
            echo    "</form>";
        }
        echo    "   <div class='fb-share-button' data-href='http://www.zhppgkaberdeen.co.uk/index.php?link=events#" . $event_content_array[$id] . "'></div>";
        echo    "   <p class='b_events_happening_date'><i>Data wydarzenia: " . $event_content_array[$happeninng_date] . "</i></p>";
        echo    "   <p class='b_events_content'>" . $event_content_array[$content] . "</p>";
        echo    "   <p class='b_events_created_date'>Utworzono: " . $event_content_array[$created_date] . "</p>";
        echo    "   <p class='b_events_author'><b>Czuwaj!</b><br/>" . $event_content_array[$author] . "</p>";
        echo    "</span>";

    }while($event_content_array = mysqli_fetch_array( $event_table_data ));
?>

When I add tags like <img> for instance with alt="" parameter it completely ruins web page. What I mean by that is that the article container is not shown at all (I've checked that with firebug) as well as everything after the article tag (like footer for instance). What is even more strange is that this: alt="text" did not break the page but every other random word does, how ever it does not show the "text" at image at all.

Similar thing happen when I tried to create table within the post and title or target parameter, I cant remember which one.

I have tried to use htmlentities($event_content_array[$content]), htmlspecialchar($event_content_array[$content]) and mysqli_real_escape_string($do_con, $event_content_array[$content]) -> non of this helped.

Is there a way to fix that or I just need to give up using this tags/parameters?

Thank you for any help or explanation

Upvotes: 0

Views: 53

Answers (1)

user4185589
user4185589

Reputation: 117

if you are using e.g echo "<img alt="text">";try to escape the " such as alt=\"text\"

Upvotes: 1

Related Questions