We help IT Professionals succeed at work.

PHP echo insert html markup in page / MySQL

pda4me
pda4me asked
on
661 Views
Last Modified: 2013-12-12
The following snippet pulls a record from a mySQL database.  The record actually has html markup I want to have as part of the display on the page but this code seems to strip out any html markup in the result.  How do I have the <?php echo($row_WADAsample_code['post_content']); ?> echo not strip out the html markup
<?php require_once('setup.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
 
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
 
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
?>
<?php
$currentPage = $_SERVER["PHP_SELF"];
?>
<?php
if (!session_id()) session_start();
if (isset($_SESSION["sample_code_Results_QueryString"]) && ($_SESSION["sample_code_Results_QueryString"] != "") && !isset($_SERVER["QUERY_STRING"]) ){
header("Location: sample_code_Results.php?".str_replace("&totalRows_","&old_totalRows_",$_SESSION["sample_code_Results_QueryString"]));
}
else{$_SESSION["sample_code_Results_QueryString"] = isset($_SERVER["QUERY_STRING"])?$_SERVER["QUERY_STRING"]:"";
}
?>
<?php
$maxRows_WADAsample_code = 10;
$pageNum_WADAsample_code = 0;
if (isset($_GET['pageNum_WADAsample_code'])) {
  $pageNum_WADAsample_code = $_GET['pageNum_WADAsample_code'];
}
$startRow_WADAsample_code = $pageNum_WADAsample_code * $maxRows_WADAsample_code;
 
mysql_select_db($database_blogs, $blogs);
$query_WADAsample_code = "SELECT * FROM sample_code ORDER BY post_date ASC";
$query_limit_WADAsample_code = sprintf("%s LIMIT %d, %d", $query_WADAsample_code, $startRow_WADAsample_code, $maxRows_WADAsample_code);
$WADAsample_code = mysql_query($query_limit_WADAsample_code, $blogs) or die(mysql_error());
$row_WADAsample_code = mysql_fetch_assoc($WADAsample_code);
 
if (isset($_GET['totalRows_WADAsample_code'])) {
  $totalRows_WADAsample_code = $_GET['totalRows_WADAsample_code'];
} else {
  $all_WADAsample_code = mysql_query($query_WADAsample_code);
  $totalRows_WADAsample_code = mysql_num_rows($all_WADAsample_code);
}
$totalPages_WADAsample_code = ceil($totalRows_WADAsample_code/$maxRows_WADAsample_code)-1;
?>
<?php
$queryString_WADAsample_code = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_WADAsample_code") == false && 
        stristr($param, "totalRows_WADAsample_code") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_WADAsample_code = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_WADAsample_code = sprintf("&totalRows_WADAsample_code=%d%s", $totalRows_WADAsample_code, $queryString_WADAsample_code);
?>
<?php
//WA AltClass Iterator
class WA_AltClassIterator     {
  var $DisplayIndex;
  var $DisplayArray;
  
  function WA_AltClassIterator($theDisplayArray = array(1)) {
    $this->ClassCounter = 0;
    $this->ClassArray   = $theDisplayArray;
  }
  
  function getClass($incrementClass)  {
    if (sizeof($this->ClassArray) == 0) return "";
  	if ($incrementClass) {
      if ($this->ClassCounter >= sizeof($this->ClassArray)) $this->ClassCounter = 0;
      $this->ClassCounter++;
    }
    if ($this->ClassCounter > 0)
      return $this->ClassArray[$this->ClassCounter-1];
    else
      return $this->ClassArray[0];
  }
}
?><?php
//WA Alternating Class
$WARRT_AltClass1 = new WA_AltClassIterator(explode("|", "WADAResultsRowDark|"));
?>
<!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></title>
<link href="WA_DataAssist/styles/Elemental_Slate.css" rel="stylesheet" type="text/css" />
<link href="WA_DataAssist/styles/Arial.css" rel="stylesheet" type="text/css" />
</head>
 
<body>
 
 
<div class="WADAResultsContainer">
  <div class="WADAResultsHeader">
    <div class="WADAHeaderText">Search Results</div>
  </div>
  <?php if ($totalRows_WADAsample_code > 0) { // Show if recordset not empty ?>
    <div class="WADAResults">
      <div class="WADAResultsNavigation">
        <div class="WADAResultsCount">Records
          <?php echo ($startRow_WADAsample_code + 1) ?>
          to
          <?php echo min($startRow_WADAsample_code + $maxRows_WADAsample_code, $totalRows_WADAsample_code) ?>
          of
          <?php echo $totalRows_WADAsample_code ?>
        </div>
        <div class="WADAResultsNavTop">
          <table border="0" cellpadding="0" cellspacing="0" class="WADAResultsNavTable">
            <tr valign="middle">
              <td class="WADAResultsNavButtonCell" nowrap="nowrap"><?php if ($pageNum_WADAsample_code > 0) { // Show if not first page ?>
                <a href="<?php printf("%s?pageNum_WADAsample_code=%d%s", $currentPage, 0, $queryString_WADAsample_code); ?>" ><img border="0" name="First" id="First" alt="First" src="WA_DataAssist/images/Slate/Elemental_first.gif" /></a>
              <?php } // Show if not first page ?></td>
              <td class="WADAResultsNavButtonCell" nowrap="nowrap"><?php if ($pageNum_WADAsample_code > 0) { // Show if not first page ?>
                <a href="<?php printf("%s?pageNum_WADAsample_code=%d%s", $currentPage, max(0, $pageNum_WADAsample_code - 1), $queryString_WADAsample_code); ?>" ><img border="0" name="Previous" id="Previous" alt="Previous" src="WA_DataAssist/images/Slate/Elemental_back.gif" /></a>
              <?php } // Show if not first page ?></td>
              <td class="WADAResultsNavButtonCell" nowrap="nowrap"><?php if ($pageNum_WADAsample_code < $totalPages_WADAsample_code) { // Show if not last page ?>
                <a href="<?php printf("%s?pageNum_WADAsample_code=%d%s", $currentPage, min($totalPages_WADAsample_code, $pageNum_WADAsample_code + 1), $queryString_WADAsample_code); ?>" ><img border="0" name="Next" id="Next" alt="Next" src="WA_DataAssist/images/Slate/Elemental_next.gif" /></a>
              <?php } // Show if not last page ?></td>
              <td class="WADAResultsNavButtonCell" nowrap="nowrap"><?php if ($pageNum_WADAsample_code < $totalPages_WADAsample_code) { // Show if not last page ?>
                <a href="<?php printf("%s?pageNum_WADAsample_code=%d%s", $currentPage, $totalPages_WADAsample_code, $queryString_WADAsample_code); ?>" ><img border="0" name="Last" id="Last" alt="Last" src="WA_DataAssist/images/Slate/Elemental_last.gif" /></a>
              <?php } // Show if not last page ?></td>
            </tr>
          </table>
        </div>
        <div class="WADAResultsInsertButton"> </div>
      </div>
      <table class="WADAResultsTable" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <th class="WADAResultsTableHeader">Title:</th>
          <th class="WADAResultsTableHeader">Date:</th>
          <th class="WADAResultsTableHeader">News:</th>
          <th>&nbsp;</th>
        </tr>
        <?php do { ?>
          <tr class="<?php echo $WARRT_AltClass1->getClass(true); ?>">
            <td class="WADAResultsTableCell"><?php echo($row_WADAsample_code['post_title']); ?></td>
            <td class="WADAResultsTableCell"><?php echo($row_WADAsample_code['post_date']); ?></td>
            <td class="WADAResultsTableCell"><?php echo($row_WADAsample_code['post_content']); ?></td>
            <td class="WADAResultsEditButtons" nowrap="nowrap">&nbsp;</td>
          </tr>
        <?php } while ($row_WADAsample_code = mysql_fetch_assoc($WADAsample_code)); ?>
      </table>
      <div class="WADAResultsNavigation">
        <div class="WADAResultsCount">Records
          <?php echo ($startRow_WADAsample_code + 1) ?>
          to
          <?php echo min($startRow_WADAsample_code + $maxRows_WADAsample_code, $totalRows_WADAsample_code) ?>
          of
          <?php echo $totalRows_WADAsample_code ?>
        </div>
        <div class="WADAResultsNavBottom">
          <table border="0" cellpadding="0" cellspacing="0" class="WADAResultsNavTable">
            <tr valign="middle">
              <td class="WADAResultsNavButtonCell" nowrap="nowrap"><?php if ($pageNum_WADAsample_code > 0) { // Show if not first page ?>
                <a href="<?php printf("%s?pageNum_WADAsample_code=%d%s", $currentPage, 0, $queryString_WADAsample_code); ?>" ><img border="0" name="First" id="First" alt="First" src="WA_DataAssist/images/Slate/Elemental_first.gif" /></a>
              <?php } // Show if not first page ?></td>
              <td class="WADAResultsNavButtonCell" nowrap="nowrap"><?php if ($pageNum_WADAsample_code > 0) { // Show if not first page ?>
                <a href="<?php printf("%s?pageNum_WADAsample_code=%d%s", $currentPage, max(0, $pageNum_WADAsample_code - 1), $queryString_WADAsample_code); ?>" ><img border="0" name="Previous" id="Previous" alt="Previous" src="WA_DataAssist/images/Slate/Elemental_back.gif" /></a>
              <?php } // Show if not first page ?></td>
              <td class="WADAResultsNavButtonCell" nowrap="nowrap"><?php if ($pageNum_WADAsample_code < $totalPages_WADAsample_code) { // Show if not last page ?>
                <a href="<?php printf("%s?pageNum_WADAsample_code=%d%s", $currentPage, min($totalPages_WADAsample_code, $pageNum_WADAsample_code + 1), $queryString_WADAsample_code); ?>" ><img border="0" name="Next" id="Next" alt="Next" src="WA_DataAssist/images/Slate/Elemental_next.gif" /></a>
              <?php } // Show if not last page ?></td>
              <td class="WADAResultsNavButtonCell" nowrap="nowrap"><?php if ($pageNum_WADAsample_code < $totalPages_WADAsample_code) { // Show if not last page ?>
                <a href="<?php printf("%s?pageNum_WADAsample_code=%d%s", $currentPage, $totalPages_WADAsample_code, $queryString_WADAsample_code); ?>" ><img border="0" name="Last" id="Last" alt="Last" src="WA_DataAssist/images/Slate/Elemental_last.gif" /></a>
              <?php } // Show if not last page ?></td>
            </tr>
          </table>
        </div>
      </div>
    </div>
  <?php } // Show if recordset not empty ?>
  <?php if ($totalRows_WADAsample_code == 0) { // Show if recordset empty ?>
    <div class="WADANoResults">
      <div class="WADANoResultsMessage">No results for your search</div>
      <div> </div>
    </div>
  <?php } // Show if recordset empty ?>
</div>
</body>
</html>
<?php
mysql_free_result($WADAsample_code);
?>

Open in new window

Comment
Watch Question

Mark BradyPrincipal Data Engineer
CERTIFIED EXPERT

Commented:
mysql_real_escape_string($theValue) is actually stripping out the special characters. You might need to write a basic sql query that just extracts the data without formatting it then echo or print it like it is and it should render properly for you.

Author

Commented:
I think I understand what you are saying.  Can you provide a sample so I can compare the two?
Mark BradyPrincipal Data Engineer
CERTIFIED EXPERT

Commented:
All you need to do is find every instance of 'mysql_real_escape_string' in your code and remove it. Then try running your page again and see if the html special characters should still be there. I'm not sure how to edit your actual function but try writing a simple mysql statement. You have so many functions on your page it's confusing to me. If you give me your table name and the column names of where the HTML code is I can write you a simple query to echo the html page.
Principal Data Engineer
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.