Styles2304 Posted November 20, 2008 Share Posted November 20, 2008 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. Quote Link to comment Share on other sites More sharing options...
Styles2304 Posted November 21, 2008 Author Share Posted November 21, 2008 Is there any way to easily convert the data in the input boxes back and forth to something that the database can handle? Although . . . I still don't understand why the html would give it problems . . . Quote Link to comment Share on other sites More sharing options...
Styles2304 Posted November 21, 2008 Author Share Posted November 21, 2008 Bump Quote Link to comment Share on other sites More sharing options...
Maq Posted November 21, 2008 Share Posted November 21, 2008 I think you're looking for this. When you store the HTML in the DB you need to use this function. htmlspecialchars() Quote Link to comment Share on other sites More sharing options...
Styles2304 Posted November 21, 2008 Author Share Posted November 21, 2008 ah thankyou! I'll test real quick. Quote Link to comment Share on other sites More sharing options...
Styles2304 Posted November 22, 2008 Author Share Posted November 22, 2008 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. Quote Link to comment Share on other sites More sharing options...
Styles2304 Posted November 22, 2008 Author Share Posted November 22, 2008 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? Quote Link to comment Share on other sites More sharing options...
Styles2304 Posted November 22, 2008 Author Share Posted November 22, 2008 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? Quote Link to comment Share on other sites More sharing options...
thebadbad Posted November 22, 2008 Share Posted November 22, 2008 unserialize($Data) should return an array, right? You can't simply echo an array. Quote Link to comment Share on other sites More sharing options...
thebadbad Posted November 22, 2008 Share Posted November 22, 2008 And when you insert the serialized data, you should run it through mysql_real_escape_string() (if not magic quotes is turned on), 'cause it can contain single quotes. Quote Link to comment Share on other sites More sharing options...
Styles2304 Posted November 23, 2008 Author Share Posted November 23, 2008 Yeah . . . still doesn't work but I figure screw it. I'm just gonna use the database the way it's meant to be used and forget the work with arrays. Thank for everyones help so far though. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.