Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Sep 2010
    Posts
    331
    Thanks
    9
    Thanked 6 Times in 6 Posts

    User posts not making it through to the database intact

    When storing user-created posts inside of the database, some of the post doesn't seem to make it through. For example, a user could post something like, "this isn't working" and only "this isn't" could be found in the database. It seems to be fine when using plain text but because I've implemented the "rich text iframe" when using any of the rich text features this problem occurs. It doesn't always occur. It seems to be hit and miss at best.
    Coding is a challenge, get used to it
    Always remember to debug
    Try the guess & check method
    Break it down into simple steps

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    Well you will need to debug that then!

    Unless you show us any code, we can't advise you.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #3
    Regular Coder
    Join Date
    Sep 2010
    Posts
    331
    Thanks
    9
    Thanked 6 Times in 6 Posts
    Ah sorry about that.
    The wyisiwyg rich-text iframe
    PHP Code:
    <div id="wysiwyg">
                            <
    h1 class="special">What's up?</h1>
                            <form id="rtfform" method="POST" name="rtfform">'
    ;
                            echo 
    "
                                <input type='hidden' name='author' id='author' value='$_SESSION[username]' />"
    ;
                                echo 
    '
                                <iframe name="richTextField" id="richTextField"></iframe>
                                <br />
                                <div id="wysiwyg_bottom">
                                    <a id="bld" class="button" href="#">B</a>
                                    <a id="undrline" class="button" href="#">U</a>
                                    <a id="italic" class="button" href="#">I</a>
                                    <a id="fontColor" class="button" href="#">Color</a>
                                    <a id="unlist" class="button" href="#">UL</a>
                                    <a id="orlist" class="button" href="#">OL</a>
                                    <a id="imge" class="button" href="#">Image</a>
                                    <input id="sbmt" class="submit_button" type="button" name="submit" value="Post" />
                                </div>
                                <p id="status"></p>
                            </form>
                        </div>'

    AJAX Submitting:
    Code:
    function sendData() {
    	var hr = new XMLHttpRequest();
    	var url = "rtf.php";
    	var usrname = $('author').value;
    	var txtField = window.frames['richTextField'].document.body.innerHTML;
    	var vars = "author="+usrname+"&post="+txtField;
    	hr.open("POST", url, true);
    	hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    	hr.onreadystatechange = function() {
    	if (hr.readyState === 4 && hr.status === 200) {
    		var return_data = hr.responseText;
    		$('status').innerHTML = return_data;
    		window.frames['richTextField'].document.body.innerHTML = '';
    	}
    }
    	hr.send(vars);
    	$('status').innerHTML = "Posting...";
    	}
    In case you're wondering, this is pure javascript. Not jQuery as it looks. I've got a $ function in the code that very basically mimics jQuery's and reduces the need for repeating document.getElementById()
    PHP Code:
    <?php
    session_start
    ();
    if (isset(
    $_POST['post'])) {
        if (
    function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc())
            {
            
    $_POST['post'] = stripslashes($_POST['post']);
            }
        
    $author $_POST['author'];
        
    $post $_POST['post'];
        
    $con = new PDO(DB_DSNDB_USERNAMEDB_PASSWORD);
        
    //set how pdo will handle errors
        
    $con->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION);
        
    $postSQL "INSERT INTO `posts` (`author`, `post`, `date`) VALUES (:author, :post, NOW())";
        
    $postQ $con->prepare($postSQL);
        
    $postQ->bindParam(':author'$authorPDO::PARAM_STR);
        
    $postQ->bindParam(':post',  $postPDO::PARAM_STR);
        
    $postQ->execute();
        }
    ?>
    On further inspection could it actually be the stripslashes code block that's causing this?
    Last edited by elitis; 05-12-2013 at 02:43 PM.
    Coding is a challenge, get used to it
    Always remember to debug
    Try the guess & check method
    Break it down into simple steps

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,026
    Thanks
    2
    Thanked 315 Times in 307 Posts
    How do you know the input is being cut off? Is this based on looking directly in the database using a tool like phpmyadmin or is it based on displaying the output on web page in your browser?

    If it is based on the output in the browser, what do you get if you do a 'view source' of the output?
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #5
    Regular Coder
    Join Date
    Sep 2010
    Posts
    331
    Thanks
    9
    Thanked 6 Times in 6 Posts
    Both based on the output in the browser as well as from the database. In both cases a portion of the input is cut off. At the moment I can't check the source, but when I get on my computer I'll give you an update on what is in the source.

    Edit: In the source, the output is cut off as well.
    For example:
    Code:
    <article id="79" class="post">
    <div id="pid" style="display:none;">2</div>
    <img style="border-radius:5px;float:left;margin:0px 5px 5px 0px;" src="/users/Elitis/images/388052_192835477474262_1081710041_n.jpg" alt="Full Name" width="75" height="75">
    <p style="float:right;display:inline;opacity:0.5;">2 months ago</p>
    <a class="ltp" href="/profile?uid=2">Full Name</a>
    <h4>@Elitis</h4>
    <p>What's left to do:</p>
    <a id="cmt79" href="#" class="postnav" onclick="activateComments(" 79")">Comment</a>
    <a id="like79" href="#" class="postnav">Like</a>
    <a id="share79" href="#" class="postnav">Next</a>
    <!--Commenting-->
    <form class="cmtForm" style="display:none;margin-bottom:1%;">
    <textarea placeholder="Reply to this post" style="width:100%;"></textarea>
    <input class="pcmt" type="button" value="Comment">
    </form>
    						</article>
    Last edited by elitis; 05-12-2013 at 09:37 PM.
    Coding is a challenge, get used to it
    Always remember to debug
    Try the guess & check method
    Break it down into simple steps


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •