Jump to content

Where is the problem in this javascript/ajax script


TeddyKiller

Recommended Posts

I have a wall post thing, and.. well you comment on it, but.. when i submit a post, it brings down the 'loading comment' and it disappears - as it should do.

 

But the php script doesn't execute, it doesn't even add it to the database.. I cant think of where the problem is.

 

Ajax/javacript

$(function() {       
    //Update Message...
    $(".post").click(function() {
       var boxval = $("#message").val();

       if(boxval=='') {
           alert("Please Enter Some Text");
       } else {
           $("#flash").show();
           $("#flash").fadeIn(400).html('<span class="loading">Loading Comment...</span>');

           $.ajax({
               type: "POST",
               url: "update_wall.php",
               data: {upd: "2", content: boxval},
               cache: false,
               success: function(html){
                   $("div#update").prepend(html);
                   $("div#update").slideDown("slow");
                   document.getElementById('content').value='';
                   document.getElementById('content').focus();
                      $("#flash").hide();
               }
           });
       } 
       return false;
    });
});

 

PHP

<?php require_once("include/config.php"); 

if(!$session->logged_in) : redirect("/index.php"); endif;

if($_POST['upd'] == '1')
{
    if(isset($_POST['content']))
    {
        $content = clean($_POST['content'],1,0,0);
    
        $time = time();

        $query = $db->execute("INSERT INTO horblewall (user_id, comment, posted) VALUES ('$user->id', '$content', '$time')");
    
        $query = $db->execute("SELECT w.*, u.avatar, u.displayname FROM horblewall as w, users as u WHERE u.id = w.user_id ORDER BY w.posted DESC");

        $row = $db->fetchassoc($query);
      
        echo '<div style="border-bottom:1px solid #e11919;" class="bar'.$row['id'].'">
                
            <div style="text-align:left; min-height:90px;">
                    
                <div style="float:right; width:105px;">
                    Posted on<br />'.date("d.m.y H:i", $row['posted']).'
                    <br /><br />
                    Msg no. '.$row['id'].'
                    <br />';
            
                    if($user->level == '9')
                    {
                        echo '<br />
                        <span class="delete_button"><a href="#" id="'.$row['id'].'" class="delete_update">Delete</a></span>';
                    }
                    else if($row['user_id'] == $user->id)
                    {
                        echo '<br />
                        <span class="delete_button"><a href="#" id="'.$row['id'].'" class="delete_update">Delete</a></span>';
                    }
                        
                echo '</div>
                            
                <div style="float:left; width:80px; text-align:center;">
                    <img src="resize_image.php?file='.$row['avatar'].'&size=70" />
                    <br />
                    <a href="#">'.$row['displayname'].'</a>
                </div>
            
                <div style="margin-right:120px; margin-left:95px;"><p>'.$row['comment'].'</p></div>
                        
            </div>
        </div>';
    } else {
        echo 'Message empty';
    }
}
?>

 

Wheres the problem? I've removed the redirection from the php, and.. well, same thing happens =[

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.