Jump to content

[SOLVED] Array Data being put in database as blank


Styles2304

Recommended Posts

I'm creating a web editor similar to the one Angelfire uses for my Church. The problem is whenever I input a certain bit of html in the text boxes, it causes the data to be stored in the database empty. It's not actually emptying the array as I've dumped it after it writing to the array to test it.

 

Here's the code that updates the database:

<?php
if ($_GET['mode'] == 'update') {
  $BlockCounter = 1;
  $BlockName = '';
  $BlockOutput = '';
  $IndexNo = $_POST['IndexNo'];
  $AdminAbilities = $_POST['AdminAbilities'];
  $PageTitle = $_POST['PageTitle'];
  $HeaderImage = $_POST['HeaderImage'];
  $IntroColor = $_POST['IntroColor'];
  $IntroContent = $_POST['IntroContent'];
  $NumBlocks = $_POST['NumBlocks'];
  
  while ($BlockCounter <= $NumBlocks) {
    $BlockName = 'Block' . $BlockCounter;
    $BlockFColor = $_POST[$BlockName . 'FColor'];
    $BlockINavYN = $_POST[$BlockName . 'INavYN'];
    $BlockDNavYN = $_POST[$BlockName . 'DNavYN'];
    $BlockTitle = $_POST[$BlockName . 'Title'];
    $BlockContent = $_POST[$BlockName . 'Content'];
    
    $BlockOutput[$BlockName]= array("FontColor" => "$BlockFColor", "INavYN" => "$BlockINavYN", "DNavYN" => "$BlockDNavYN", "Title" => "$BlockTitle", "Content" => "$BlockContent");
    $BlockCounter++;
  }

$BlockArray = array("PageTitle" => "$PageTitle", "HeaderImage" => "$HeaderImage", "Introduction" => array("FontColor" => "$IntroColor", "Content" => "$IntroContent"), "NumberOfBlocks" => $NumBlocks, "Blocks" => $BlockOutput);

$BlockArray = serialize($BlockArray);

$query = "UPDATE ExtraContent SET Data = '" . $BlockArray . "' WHERE IndexNo = " . $IndexNo . ";";

mysql_query($query,$link) or die(mysql_error());

header('Location: page_editor.php?mode=main#top');
}
?>

 

And now the code that is causing problems. It's nothing special just a table with times and descriptions:

<table width="90%" cellpadding="0" cellspacing="0" border="0">
  <tr>
    <td width="20%" valign="top" align="left">
      <font color="FF0000">
      5:30 p.m.
    </td>
    
    <td width="*" valign="top" align="left">
      <font color="FF0000">
      Registration
    </td>
  </tr>
  
  <tr>
    <td width="20%" valign="top" align="left">
      <font color="FF0000">
      6:00 p.m.
    </td>
    
    <td width="*" valign="top" align="left">
      <font color="FF0000">
      Large Group Session (praise and worship, presentation of this week's lesson, testimony, special music)
    </td>
  </tr>
  
  <tr>
    <td width="20%" valign="top" align="left">
      <font color="FF0000">
      7:00 p.m.
    </td>
    
    <td width="*" valign="top" align="left">
      <font color="FF0000">
      Small Group Breakout Sessions
    </td>
  </tr>
  
  <tr>
    <td width="20%" valign="top" align="left">
      <font color="FF0000">
      8:00 p.m.
    </td>
    
    <td width="*" valign="top" align="left">
      <font color="FF0000">
      Covenant Café (light refreshments and informal conversation)
    </td>
  </tr>
  
  <tr>
    <td width="20%" valign="top" align="left">
      <font color="FF0000">
      8:30 p.m.
    </td>
    
    <td width="*" valign="top" align="left">
      <font color="FF0000">
      Adjourn
    </td>
  </tr>
</table>

 

Note: I've tested the html problems and it seems to be tables that cause the problem.

Link to comment
Share on other sites

thought I posted a reply but I guess not. That didn't do it.

 

Just a refresher, anything I enter in the fields will work until I start dropping in html, specifically table codes.

 

I implemented the code like so:

<?php
$BlockContent = htmlspecialchars($_POST[$BlockName . 'Content']);
?>

 

Anyone else have any ideas? I'm kind of at a stand still until I can get this worked out and I've exhausted my resources.

Link to comment
Share on other sites

Ok . . . I found the problem so NOW I just need help fixing it hahaha.

 

The problem is the unserialize. The data is being stored just fine in the data base and when I retrieve it plain, it is being retrieved just fine. However, it is only being retrieved in its serialized form:

 

<?php
  while ($row = mysql_fetch_array($result)) {
    $IndexNo = $row['IndexNo'];
    $EditTitle = $row['Title'];
    $Data = $row['Data'];
  }
  echo 'Plain Data: ' . $Data . '<br>';
  echo 'Unserialized Data: ' . unserialize($Data) . '<P>';
?>

 

The 'Plain Data" like I said, echos back the still serialized data from the database. However, the 'Unserialized Data' echos back nothing. Any idea why the html is causing it to not be able to unserialize the data?

 

EDIT: Even More info . . . a table code works just fine until I try to define any characteristics of the table like width. What the f is going on here? How does adding, what appears to be, quotes jack up the whole process?

Link to comment
Share on other sites

Well, tried to edit again to avoid double posting but too late I guess.

 

It appears that it IS anything with quotes. If I drop in "test" in any of the fields, it jacks up the whole unserialize process. So, I believe that should be sufficient data for someone to tell me how I'm screwing up?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.