TinyMCE not saving to mySQL all the time

Discussion in 'PHP' started by mokimofiki, Nov 4, 2010.

  1. #1
    I have TinyMCE included in a form that once submitted saves to mySQL.

    My issue is that when filling all fields except the tinymce ones the form submits and saves to te database. Although when filling in the TinyMCE fields nothing will save to tehe database at all.

    Below is my form and processor:

    Form:
    <form method="post" action="postblog.php">
    <table>
    <tr>
    <td align="left">Title of the Blog: </td><td align="left"><input type="text" name="title" id="title"></td>
    </tr><tr>
    <td align="left">Date of the Blog: </td><td align="left"><input type="text" name="date" id="date"></td>
    </tr><tr>
    <td align="left">Category of the Blog: </td><td align="left"><select name="category" id="category">
    <option type="text" value="Advertising">Advertising</option>
    <option type="text" value="Design">Design</option>
    <option type="text" value="Development">Development</option>
    <option type="text" value="Hosting">Hosting</option>
    <option type="text" value="SEO">SEO</option>
    <option type="text" value="Tutorials">Tutorials</option>
    </select></td>
    </tr>
    </table>
    <br />
    
    Mini Description:<br />
    <textarea name="minidesc" id="minidesc" rows="10" cols="40" style="width: 80%"></textarea>
    <br /><br />
    
    Full Blog:<br />
    <textarea id="elm1" name="elm1" rows="15" cols="80" style="width: 80%"></textarea>
    <br />
    <input type="submit" name="add" id="add" value="Add Blog">
    </form>
    Code (markup):
    Processing:
    mysql_query("INSERT INTO blog (title, category, date, message, minidesc, views) VALUES ('$_POST[title]', '$_POST[category]', '$_POST[date]', '$_POST[elm1]', '$_POST[minidesc]', '0')");
    Code (markup):
     
    mokimofiki, Nov 4, 2010 IP
  2. ivan.kristianto

    ivan.kristianto Active Member

    Messages:
    136
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #2
    try print_r($_POST[elm1]) or var_dump($_POST[elm1]) to see if it is not empty.
     
    ivan.kristianto, Nov 4, 2010 IP
  3. mokimofiki

    mokimofiki Well-Known Member

    Messages:
    444
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #3
    Thank you for the reply but I just figured it out. mySQL query stops in the middle of saving due to some of the html code that it thinks is php. adding addslashes() to the message when saving fixes it.
     
    mokimofiki, Nov 4, 2010 IP
  4. ivan.kristianto

    ivan.kristianto Active Member

    Messages:
    136
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #4
    Don't forget to make safe sql query to prevent SQLi.
     
    ivan.kristianto, Nov 4, 2010 IP
  5. sabaina

    sabaina Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    you can also try using mysql_escape_string()
     
    sabaina, Nov 4, 2010 IP
  6. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #6
    This is a deprecated function as of 5.3, I would advise using mysql_real_escape_string instead.
     
    ThePHPMaster, Nov 7, 2010 IP
  7. themullet

    themullet Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #7
    Nice knowledge on the deprecation of it, just updating a few scripts now from that, thanks.

    Looks like it's going to be a quotes problem, as these guys said escape the string, also you can add mysql_query () or die(mysql_error()); to give what the error is
     
    themullet, Nov 8, 2010 IP