Jump to content


  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About Loois

  • Rank
  • Birthday 06/16/1997

Previous Fields

  • Languages
    Italiano, Inglese, Francese

Contact Methods

  • Website URL

Profile Information

  • Gender
  • Location
  1. Loois

    Issues comments

    comment.sql CREATE TABLE `comment` ( `user_id` int(8) NOT NULL, `photo_id` int(8) NOT NULL, `comment` text NOT NULL, `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`user_id``photo_id`) ); ajax_comment.php <?php // code will run if request through ajax if (isset( $_SERVER['HTTP_X_REQUESTED_WITH'] )): include('../config.php'); // connecting to db dbConnect(); if (!empty($_SESSION['user_id']) AND !empty($_POST['photo_id']) AND !empty($_POST['comment'])) { // preventing sql injection $user_id = $_SESSION['user']; $photo_id = $_POST['photo_id']; $comment = $_POST['comment']; // insert new comment into comment table $query = "INSERT INTO comment (user_id, photo_id, comment) VALUES('$user_id', '$photo_id', '$comment')"); } ?> <!-- sending response with new comment and html markup--> <div class="comment-item"> <div class="comment-avatar"> <a href="<?php echo $baseurl . "/" . $photo_username ?>"><img src="./core/getimg.php?profiloimg=<?php echo $photo_userid ?>" class="home-foto-profilofoto" /></a> </div> <div class="comment-post"> <h3><?php echo $photo_username . "/" . $user_id ?> <span>ha commentato:</span></h3> <p><?php echo $comment?></p> </div> </div> <?php // close connection dbConnect(0); endif?> jQuery.js <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script> $(document).ready(function(){ var form = $('form'); var submit = $('#submit'); form.on('submit', function(e) { // prevent default action e.preventDefault(); // send ajax request $.ajax({ url: 'ajax_comment.php', type: 'POST', cache: false, data: form.serialize(), //form serizlize data beforeSend: function(){ // change submit button value text and disabled it submit.val('Submitting...').attr('disabled', 'disabled'); }, success: function(data){ // Append with fadeIn see http://stackoverflow.com/a/978731 var item = $(data).hide().fadeIn(800); $('.comment-block').append(item); // reset form and button form.trigger('reset'); submit.val('Submit Comment').removeAttr('disabled'); }, error: function(e){ alert(e); } }); }); }); </script> home.php (Where there are my users posts) <!-- Commenti --> <form id="form" method="post"> <!-- need to supply post id with hidden fild --> <input type="hidden" name="comment" value="1"> <label> <a href="<?php echo $baseurl . "/" . $photo_username ?>"><img width="25" height="25"src="./core/getimg.php?profiloimg=<?php echo $photo_userid ?>" class="home-foto-profilofoto" /></a> </label> <label> <a href="<?php echo $baseurl . "/" . $photo_username; ?>"><?php echo $photo_username; ?></a> </label> <label> <span>Commenta</span> <textarea name="comment" id="comment" cols="0" rows="0" placeholder="Scrivi un commento.." required></textarea> </label> <input type="submit" id="submit1" value="Submit Comment"> </form> <?php include ("ajax_comment.php"); include ("jquery.js"); ?> <!-- Fine commenti -->
  2. Loois

    Issues comments

    I actually had problems with comments.php i can not establish the function, i form i already keep it alike but i can not create the function behind. Can not you help me?
  3. Loois

    Issues comments

    Someone would give me a hand in creating a comment form for my users posts, unfortunately I can not. from contact : leccialoois@me.com my website: http://www.socialedge.altervista.org/
  • Create New...