PHP - Moved: Vote On A Comment And Hide The Comment If Vote Becomes Negative (ajax/php)
This topic has been moved to Ajax Help.
http://www.phpfreaks.com/forums/index.php?topic=322815.0 Similar TutorialsHi everyone, I have a like button on repeating regions that is used for keeping a record of votes on comments. People click it an it adds 1 to the votes column total. It works just fine. Problem is i only want to a allow a user one vote per comment only. can vote on other comments as well, but again, only one vote per day per comment. i wouldn't know where to start. Would i use a cookie or record an ip? switch ($_REQUEST['action']) { case 'likeit'; foreach($_REQUEST as $key=>$value){ $$key = $value; } $votes = $_GET['votes']; $total = ($votes + 1); $sql = mysql_query("UPDATE quotes SET votes = '$total' WHERE quoteid = '$quoteid'"); break; } This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=333432.0 CREATE TABLE posts ( postId INT(11) NOT NULL UNIQUE AUTO_INCREMENT, title VARCHAR(255) NOT NULL, author VARCHAR(24) NOT NULL, description TEXT NOT NULL, createdAt TIMESTAMP, PRIMARY KEY (postId) ); CREATE TABLE comments( commentId INT(11) NOT NULL UNIQUE AUTO_INCREMENT, comment TEXT NOT NULL, postId INT(11), userId INT(11), createdAt TIMESTAMP, PRIMARY KEY (commentId), FOREIGN KEY (userId) REFERENCES users(userId), FOREIGN KEY (postId) REFERENCES posts(postId) ); CREATE TABLE replies ( repId INT(11) NOT NULL UNIQUE AUTO_INCREMENT, reply TEXT NOT NULL, userId INT(11), commentId INT(11), createdAt TIMESTAMP, PRIMARY KEY (repId), FOREIGN KEY (userId) REFERENCES users(userId), FOREIGN KEY (commentId) REFERENCES comments(commentId) ); CREATE TABLE users ( userId INT(11) NOT NULL UNIQUE AUTO_INCREMENT, userName VARCHAR(100) NOT NULL,, email VARCHAR(100) NOT NULL, PRIMARY KEY (userId) ); how to retrive userName,comment, and createdAt from users and comments table while I have used userId as a Foreign key on the comment table if it isn't correct, correct me please Hello, I have built a blog in php but. On each article in the blog people are able to comment. I would now like to build a system where people can vote on the comment up/down with Ajax. In my comments database I have a table that looks like this: id / article_id / user_id / dateposted / comment / voteup / votedown I would like it to look like this: Any ideas how I can do this? Tutorials online? Thanks a million Hi im trying to Make a Timer count down in this code function getTime($host, $user, $pass, $db, $hours, $ip, $serverId) { $c = @mysql_connect($host, $user, $pass); if(mysql_select_db($db, $c)) { $dateQ = mysql_query('SELECT MAX(date) AS lastVoteDate FROM `'. $db .'`.`votes` WHERE ip="'. $ip .'"') or die(mysql_error()); $getDate = mysql_fetch_assoc($dateQ); $diffrence = time() - strtotime($getDate['lastVoteDate']); $hours = number_format(($diffrence / 60 / 60)); $minutes = number_format(($hours / 60)); if(!$hours < 1){ return ("". $hours .""); } else { return ("0"); } } else { return array(1, "Error connecting to DB."); } } I get to errors below and cannot figure out what im doign wrong i've tryed diffrent ways and have even rewritten this couple times (#1error) not sure how to re query and echo out the array?? (#2error) gives me error on line 14 if i echo anything past (echo $row['name']."|user1:". $row['user1']. "|user2:". $row['user2']. ->this Code: [Select] <?php $conn = mysql_connect("localhost", "root", ""); if (!$conn) { echo "Unable to connect to DB: " . mysql_error(); } if (!mysql_select_db("register_db")) { echo "Unable to select mydbname: " . mysql_error(); exit; } $result = mysql_query("SELECT * FROM register_vote WHERE name = '{$_POST['user']}'"); if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit; } =========================(#1error)========================================== //THIS IS THE CODE I'M HAVING ISSUES WITH if (mysql_num_rows($result) == 0) { mysql_query("INSERT INTO register_vote (name) VALUES ('$_POST[user]')"); //need it to the query new results after insert //then // echo $row['name']."|user1:". $row['user1']. "|user2:". $row['user2']. "|user3:". $row['user3']; }================================================= (#2error)=================================== while ($row = mysql_fetch_array($result)) { echo $row['name']."|user1:". $row['user1']. "|user2:". $row['user2']. "|user3:". $row['user3']; } //when I put anything past $row['user2']. it gives me error on line 14 mysql_free_result($result); ?> Hi, I run a top site which has incentives. Originally when a voter came and voted, the script in the background would run file() but I noticed that it sometimes lagged and caused the voter to wait a few secs before the page loads. I was then told by a developer to use file_get_contents(), but I was getting the same results. It occasionally lagged, even on my own websites that are voting on it. I decided to log the incentives now, and get a cron to check and process any incentives instead of the user lagging, but now it's starting to kill my server as you can see below Quote xxxxx.com 1.05 0.49 0.1 Top Process %CPU 77.2 php -q process_incentives.php Top Process %CPU 24.0 php -q process_incentives.php Top Process %CPU 8.0 php -q timers/5mins.php xxxxx.com 0.99 0.13 0.0 Top Process %CPU 9.0 php -q timers/30mins.php Top Process %CPU 7.0 php -q timers/5mins.php Code in process_incentives.php //REWARD VOTERS $get = mysql_query("SELECT id,url FROM incentives ORDER BY id DESC limit 50;"); while ($game = mysql_fetch_array($get)){ file_get_contents("$game[url]"); mysql_query("DELETE from incentives WHERE id='$game[id]'"); } I'm currently trying to break apart some PHP coding that a former coder created, but left no documentation to. Can anyone help e find the function in this mess that creates the vote button and passes the currently loaded data to the next page? Here's the original code: Code: [Select] <?php include("./templates/mysql_connect.php"); //FOR LETTER: A $query = "SELECT * FROM seniors WHERE last_name LIKE 'A%' ORDER BY last_name ASC"; $result = @mysql_query ($query); echo '<table><tr> <td> <p><span class="style19"><u>-A-</u></span><br />'; while ($row = mysql_fetch_array ($result)){ echo "<a href=\"$row[pic_url]\" rel=\"lightbox[seniors]\" title=\" <form action ="/sencha-tallyvote.php?sen_id=$row[sen_id]" method="post"> $row[first_name] $row[last_name] - $row[school] <br /> <input name="submit" align="right" type="submit" value="Vote" > </form> \">$row[last_name], $row[first_name]</a><br/>"; } echo '</p>'; ?> The original code used a lightbox feature with an added voting button tagged on near the bottom. We've Xed the lightbox feature and are trying to deconstruct it into tangible PHP pages. We have everything done except for the coding for the vote button. Here's our coding for the currently deconstructed page, and where the coding for the button needs to go: Code: [Select] <?php require_once('templates/mysql_connect.php'); ?> <?php $query = "SELECT * FROM seniors WHERE sen_id=$_GET[sen_id]"; $result = mysql_query ($query); $row = mysql_fetch_array ($result); ?> <div class="contents"> <h1><?php echo $row['first_name'], " ", $row['last_name']; ?></h1> <h4><?php echo $row['school']; ?></h4> </div> <?php echo '<a href="sencha.php" class="bigmenu"><img src="images/backarrow.png" alt="Back to Senior Challenge Home" class="arrowleft indexicon" /><u>Back</u></a><br />'; ?> <?php echo "<img src=\"http://www.rutholsonphoto.com" .$row['pic_url']. "\" width=\"100%\" />" ?> <br /> <br /> <a href="/">{{VOTEBUTTON}}</a> Any experienced help will be greatly appreciated. Hey. I just needed a little help with a voting system for articles I've put together in PHP. Essentially what happens is someone clicks the "Vote up" button which takes them to the "voteup.php" page. This is the "voteup.php" page where it updates the database for that given article and increments the "votes" column by one. This works perfectly. But the problem is people can do this infinite times and give articles infinite votes. I need it so that each IP address can only vote on each specific article once. Any ideas on how this could be done? Voteup.php Code: [Select] <?php include("connect.php"); $id2 = $_GET['id']; // Get the ID of the article that will be voted up $con = mysql_connect("localhost","lconditn_admin","hello"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("lconditn_database", $con); mysql_query("UPDATE base SET votes = votes+1 // Add one vote to the article WHERE id2 = '$id2'"); mysql_close($con); ?> Thanks a lot for any help with this. Hi, I'm currently using a voting script, but have a problem with people voting more then once, and want to add a way to keep the voting unique and 1 per person via IP check can anybody assist me how to implement it in the following script please?
<?php // the questions and the answers $pool_question="Do you think I should keep Galaxy Universe open?"; $pool_option[1]="Yes"; $pool_option[2]="No"; // If counter files are not available,they will be created // You may remove next lines after the first use of the script if (!file_exists("pool_5483543_1.txt")){ // next two lines will not work if writing permissions are not available // you may create the files bellow manualy with "0" as their unique content file_put_contents ("pool_5483543_1.txt",0); file_put_contents ("pool_5483543_2.txt",0); } // retrieve data saved in files $pool_responses[1]=file_get_contents("pool_5483543_1.txt"); $pool_responses[2]=file_get_contents("pool_5483543_2.txt"); // if user votes, increase corresponding value if ($_POST["5483543"] and $_POST["5483543b"]==""){ if ($_POST["5483543"]==1) {$pool_responses[1]++;file_put_contents("pool_5483543_1.txt",$pool_responses[1]);} if ($_POST["5483543"]==2) {$pool_responses[2]++;file_put_contents("pool_5483543_2.txt",$pool_responses[2]);} } // get percentajes for each answer in the pool // get total number of answers $total_responses=$pool_responses[1]+$pool_responses[2]; if ($total_responses==0){$total_responses=1;} // to avoid errors at start // compute percentajes (with one decimal number) $pool_percentaje[1] = round((100*$pool_responses[1])/$total_responses,1); $pool_percentaje[2] = round((100*$pool_responses[2])/$total_responses,1); // print the form, which includes de answers and the percentajes print "<center>\n"; print "<form method=post action=".$_SERVER["PHP_SELF"].">\n"; print "<b>".$pool_question."</b>\n"; print "<table cellpadding=4>\n<br>"; // answer 1 print "<tr>\n"; print "<td><input type=radio name=5483543 value=1> ".$pool_option[1]."</td>\n"; print "<td bgcolor=DDDDFF>" .$pool_responses[1]." (".$pool_percentaje[1]."%)</td>\n"; print "</tr>\n"; // answer 2 print "<tr>\n"; print "<td><input type=radio name=5483543 value=2> ".$pool_option[2]."</td>\n"; print "<td bgcolor=DDDDFF>" .$pool_responses[2]." (".$pool_percentaje[2]."%)</td>\n"; print "</tr>\n"; print "</table>\n"; // a simple control to avoid one user to vote several times if ($_POST["5483543"]){ print "<input type=hidden name=5483543b value=1>\n"; } print "<input TYPE=submit value=Add my answer>\n"; print "</form>\n"; print "</center>\n"; ?>The reason why I ask for IP check is I wan't to use $_SERVER["HTTP_X_MXIT_USERID_R"];in the place of the Ip since it give a unique name via the platform I want to implement it. Edited by cobusbo, 14 January 2015 - 01:49 PM. I am using the dragdrop functionality on a page which also updates the database.Drag and drop is working fine But i am having difficulty to determine which events to use to update the database. Here is my code
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery UI Sortable - Portlets</title> <link rel="stylesheet" href="//code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css"> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="//code.jquery.com/ui/1.11.1/jquery-ui.js"></script> <!--<link rel="stylesheet" href="/resources/demos/style.css">--> <style> body { min-width: 520px; } .interview-questions-column { width: 400px; float: left; padding-bottom: 100px; } .question-bank { width: 500px; float: left; padding-bottom: 100px; } .portlet { margin: 0 1em 1em 0; padding: 0.3em; } .portlet-header { padding: 0.2em 0.3em; margin-bottom: 0.5em; position: relative; } .portlet-toggle { position: absolute; top: 50%; right: 0; margin-top: -8px; } .portlet-content { padding: 0.4em; } .portlet-placeholder { border: 1px dotted black; margin: 0 1em 1em 0; height: 50px; } .sortable { border: 1px solid #eee; width: 95%; min-height: 20px; list-style-type: none; margin: 0; padding: 5px 0 0 0; float: left; margin-right: 10px; } .sortable li { margin: 0 5px 5px 5px; padding: 5px; font-size: 1.2em; width: 95%; } .bank-quertion-sotrable { border: 1px solid #eee; width: 150px; min-height: 20px; list-style-type: none; margin: 0; padding: 5px 0 0 0; float: left; margin-right: 10px; } .bank-quertion-sotrable li{ margin: 0 5px 5px 5px; padding: 5px; font-size: 1.2em; width: 200px; } .ui-state-default { height: 1.5em; line-height: 1.2em; } </style> <script> $(function() { $( ".interview-questions-column" ).sortable({ connectWith: ".interview-questions-column", handle: ".portlet-header", cancel: ".portlet-toggle", placeholder: "portlet-placeholder ui-corner-all" }); $( ".portlet" ) .addClass( "ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" ) .find( ".portlet-header" ) .addClass( "ui-widget-header ui-corner-all" ) .prepend( "<span class='ui-icon ui-icon-minusthick portlet-toggle'></span>"); $( ".portlet-toggle" ).click(function() { var icon = $( this ); icon.toggleClass( "ui-icon-minusthick ui-icon-plusthick" ); icon.closest( ".portlet" ).find( ".portlet-content" ).toggle(); }); }); $(function() { $( ".sortable" ).sortable({ placeholder: "ui-state-default", connectWith: ".connectedSortable", /*receive: function(event, ui) { // only perform for sub drop downs if($(this).hasClass('question_bank')) { // if the item doesn't have the matching sub class if (!$(this).hasClass($(ui.item).attr('class'))) { // cancel the sortable $(ui.sender).sortable('cancel'); } } alert('receive'); alert(ui.sender.attr("dataid")); alert(ui.sender.toSource()); // alert("[" + this.id + "] received [" + ui.item.attr("id") + "] from [" + ui.sender.attr("id") + "]"); },*/ update: function (event, ui) { //serial = $('#sortableF').sortable('serialize'); var data = $(this).sortable('serialize'); alert(data); //alert('update sortable'); //alert("[" + this.id + "] received [" + ui.item.attr("id") + "] from [" + ui.sender.attr("id") + "]"); // POST to server using $.post or $.ajax /*$.ajax({ data: 'test', type: 'POST', url: '/your/url/here' });*/ } }).disableSelection(); }); $(function() { $( ".draggable" ).draggable({ connectToSortable: ".sortable", helper: "clone", /*revert: function(valid) { if(valid) { alert("drop is valid"); //Dropped in a valid location } else { alert("drop is invalid"); //Dropped in an invalid location } // return !valid; return false; }*/ stop: function( event, ui ) { // alert(ui); // alert("[" + this.id + "] received [" + ui.item.attr("id") + "] from [" + ui.sender.attr("id") + "]"); } }); }); $( "ul, li" ).disableSelection(); </script> </head> <body> <div class="interview-questions-column"> <div class="portlet"> <div class="portlet-header">Feeds</div> <div class="portlet-content"> <ul id="sortableF" class="connectedSortable sortable"> <li class="ui-state-default" id="item-1">Item 1</li> <li class="ui-state-default" id="item-2">Item 2</li> <li class="ui-state-default" id="item-3">Item 3</li> <li class="ui-state-default" id="item-4">Item 4</li> <li class="ui-state-default" id="item-5">Item 5</li> </ul> </div> </div> <div class="portlet"> <div class="portlet-header">News</div> <div class="portlet-content"> <ul id="sortableS" class="connectedSortable sortable"> <li class="ui-state-default" id="item-6">Item 1</li> <li class="ui-state-default" id="item-7">Item 2</li> <li class="ui-state-default" id="item-8">Item 3</li> <li class="ui-state-default" id="item-9">Item 4</li> <li class="ui-state-default" id="item-10">Item 5</li> </ul> </div> </div> <div class="portlet"> <div class="portlet-header">Shopping</div> <div class="portlet-content"> <ul id="sortableS" class="connectedSortable sortable"> <li class="ui-state-default" id="item-11">Item 1</li> <li class="ui-state-default" id="item-12">Item 2</li> <li class="ui-state-default" id="item-13">Item 3</li> <li class="ui-state-default" id="item-14">Item 4</li> <li class="ui-state-default" id="item-15">Item 5</li> </ul> </div> </div> <div class="portlet"> <div class="portlet-header">Links</div> <div class="portlet-content"> <ul id="sortableS" class="connectedSortable sortable"> <li class="ui-state-default" id="item-16">Item 1</li> <li class="ui-state-default" id="item-17">Item 2</li> <li class="ui-state-default" id="item-18">Item 3</li> <li class="ui-state-default" id="item-19">Item 4</li> <li class="ui-state-default" id="item-20">Item 5</li> </ul> </div> </div> <div class="portlet"> <div class="portlet-header">Images</div> <div class="portlet-content"> <ul id="sortableS" class="connectedSortable sortable"> <li class="ui-state-default" id="item-21">Item 1</li> <li class="ui-state-default" id="item-22">Item 2</li> <li class="ui-state-default" id="item-23">Item 3</li> <li class="ui-state-default" id="item-24">Item 4</li> <li class="ui-state-default" id="item-25">Item 5</li> </ul> </div> </div> </div> <div class="question-bank"> <div class="portlet"> <div class="portlet-header">Question bank</div> <div class="portlet-content"> <ul id="question_back" class="connectedSortable bank-quertion-sotrable"> <li class="ui-state-default draggable" id="item-26">Item 1</li> <li class="ui-state-default draggable" id="item-27">Item 2</li> <li class="ui-state-default draggable" id="item-28">Item 3</li> <li class="ui-state-default draggable" id="item-29">Item 4</li> <li class="ui-state-default draggable" id="item-30">Item 5</li> </ul> </div> </div> </div> </body> </html>Basically above code will form few boxes with items(which are actually questions) in it. There is one box on the right side with heading "Question Bank". From the "Question Bank" we can drag the questions to other boxes but can't do the reverse(this is also working). Also we can sort the questions within the box or drag the questions from one box to another. Box heading are the categories and items are questions associated to that categories. What i need is : Event that updates the database when we drag the questions from "Question Bank" to any box on the left side. Please note Questions in the "Question Bank" are pre created coming from database. Event that updates the database when we sort the questions within the box. Event that updates the database when we drag the question from one box to another box. it should also do the sorting for that two boxes. Event that updates the database when we sort the boxes. Here is the JS Fiddle link jsfiddle.net/6o30rrzx Question Bank is comming on the bottom of the page instead of on the right side any advice and suggestions will be greatly appreciated Thank you for reading this post. Code: [Select] <form name="commentbox" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table border="0"> <textarea name="comment" cols="20" rows="2" onclick="document.commentbox.comment.value='';" onfocus="this.style.borderColor='yellow';" onblur="this.style.borderColor='blue';" />Comment...</textarea> </td></tr> $commentcheck = $_POST['comment']; if ($commentcheck == "Comment...") { die(' <META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=index.php\"> '); }else why does this not refresh if i comment "Comment..." it just dies and doesnt echo anything Okay... Since my last post about the website I was working on, I've figured out what I was asking. But now, I've run into another problem... Once I have a functional form on my website where a user inputs data and presses submit, how do I go about getting it to remain posted where directed? So if the user types his first and last name and presses submit, how do I get their input to remain posted on the page, much like a guestbook? I'm a newbie at this stuff, but it's a must for mine and my partner's website. Thanks again! PS... I have the code for the form all typed out and it works, it just displays the data with $echo rather than posting it permanantly. Hi, can anyone help show me or tell me where I can find out how I can create a comment box system that will get the members userid/username and post it with the comment when it has been submitted on the page. e.g the way youtube displays comments with the username and then the comment underneath. thanks, Good Afternoon everyone. I am having some problems in getting a script I found on a forum to work, I have tried contacting the original author but with no joy. Basically its a php/ajax comment system, however I am getting these errors Code: [Select] Notice: Undefined index: type in C:\wamp\www\buy2earn\viewm.php on line 93 Notice: Undefined index: type in C:\wamp\www\buy2earn\viewm.php on line 105 Here is the portion of code that I am working on, I don't understand what $_post['type'] is meant to come from? I guess its basically if the form has been submitted, but if I change the values tp 'submit' I still get the same result, just with the message submit is undefined instead! <?php $date=date("Y-m-d"); $username = $_SESSION['username']; if($_POST['type'] == "addcomment") { $username = mysql_real_escape_string($_POST['username']); $comment = mysql_real_escape_string($_POST['comment']); if($username == "" || $comment == "") { die("<p><font color='red'>Error: Please include a message.</font></p>"); } $q1 = mysql_query("INSERT INTO 'comments' ('c_id', 'm_id', 'username', 'date', 'comment') VALUES ('', '$m_id', '$username', '$date', '$comment')") or die("<p>Mysql Error: <b>".mysql_error()."</b></p>"); echo "<p><font color='green'>Comment added successfully.</font></p>"; } elseif($_POST['type'] == "getcomments") { $q1 = mysql_query("SELECT * FROM 'comments'"); $n1 = mysql_num_rows($q1); if($n1 == 0) { die("<p><font color='red'>No comments were found.</font></p>"); } echo "<table border=1>"; echo "<tr><td><b>User</b></td><td><b>Comment</b></td></tr>"; while($r1 = mysql_fetch_assoc($q1)) { $a = $r1['username']; $m = $r1['comment']; echo "<tr><td>$a</td><td>$m</td></tr>"; } echo "</table>"; } else {?> <div style="font-size: 18px;"> <p>Current Comments: </p> <div id="comments"></div> <hr /> <p>Add a comment:</p> <form action="<?php $_SERVER['PHP_SELF'];?>" method="post"> <p>Username: <input type="text" name="username" id="username" /></p> <p>Comment: <textarea name="message" cols="50" rows="10" id="message"></textarea></p> <p><input type="submit" name="submit" value="Add Comment" id="submit" /></p> </form> <div id="return"></div> </div> <?php } ?> Many Thanks for any help I've got a comment box that connects to a MySQL database. I've got this error message here when I use the PHP include function to call on this script on my main page http://www.inkzoid.com/index.php ... <?php // calling session_start() the function which starts our authentication session session_start(); // connecting to mysql server $l = mysql_connect ( "999.999.999.999" , "inkzoid" , "999) or die("Error connecting:<BR><BR>".mysql_error()); mysql_select_db( "inkzoid" ) or die("Error getting db:<BR><BR>".mysql_error()); // defining getShouts() which is our function that gets all of our shouts function getShouts() { echo '<div align="center"> <table width="150" border="0" cellspacing="0" cellpadding="0"> <tr> <td> '; $query = mysql_query("SELECT * FROM shouts ORDER BY id DESC LIMIT 10") or die(mysql_error()); while ($row = mysql_fetch_array($query) ) { $name = stripslashes($row['Name']); $contact = stripslashes($row['Contact']); $shout = stripslashes($row['Shout']); if(empty($contact)) { echo '<p><span class="author">'.$name.'</span> - <span class="shout">'.$shout.'</span></p>'; } else { echo '<p><span class="author"><a href="'.$contact.'" target="_blank">'.$name.'</a></span> - <span class="shout">'.$shout.'</span></p>'; } // if empty contact } // while row mysqlfetcharray query echo '<br><br>'; echo ' </td> </tr> <tr> <td height="10"> </td> <form name="shout" method="post" action="shout.php"> <div align="center"> <input name="name" type="text" id="name" value="Name" size="25" maxlength="10"><br> <input name="contact" type="text" id="contact" value="http://" size="25"><br> <input name="message" type="text" id="message" value="Message" size="25"><br> <input name="shout" type="submit" id="shout" value="Shout!"> </div> </form> </td> </tr> </table> </div> '; } // function getshouts // our processing if control statement if ( isset ( $_POST['shout'] ) ) { $name = addslashes($_POST['name']); $contact = addslashes($_POST['contact']); $message = $_POST['message']; if ( ( isset($name) ) && ( isset($message) ) ) { // getting smilie list $smilies = mysql_query("SELECT * FROM smilies") or die(mysql_error()); while($get = mysql_fetch_array ($smilies)) { $alt = $get['Alt']; $smilie = $get['URL']; $message = str_replace( $get['Symbol'] , '<img src="smilies/'.$smilie.'" border="0" width="15" height="15" alt="'.$alt.'">' , $message); $themessage = addslashes($message); // replacing all smilies } mysql_query("INSERT INTO shouts (Name, Contact, Shout) VALUES ( '$name' , '$contact' , '$message' )") or die(mysql_error()); $_SESSION['has_posted'] = 'yes'; header("Location: shout.php"); // if required fields aren't empty, process into database } else { echo '<script>alert("Some fields were not filled out!");</script>'; header("Location: shout.php"); // if required fields were left empty, show an error dialog } }/* else { echo '<script>alert("Please follow the form to this page.");</script>'; header("Location: shout.php"); // if they weren't even referred from the form, show error dialog and redirect } // if isset post shout /* STARTING THE MAIN SCRIPT NOW */ // starting the table //displaying the shouts getShouts(); mysql_close($l); ?> I was told that I should put ob_start(); at the top of my page and ob_end_clear(); at the end of my page, but should that code go on the shout.php file or my index.php file (index.php is where I want my comment box to go)? I was using session_start(); but I got some error messsages about headers already being sent because I had originally used the php include function at the top of index.php to include shout.php. After reading up on it I found out that the error was caused by not having session_start(); being the first line of code. So my problem was that I wanted the comment box to be somewhere other than at the top of the page. Not sure how to move it. Anyways I'm pretty confused right now and if someone could give me some advice it would be appreciated. Hi, I'm trying to improve my coding and would appreciate if someone could comment and alter my code. I dont know what would work best, named placeholders or question mark placeholders. Place the variables in a array first and then do the binding. Im looking also for solutions regarding record update using place holders. Thanks $idnrr = 1; $users = DB::getInstance()->query("SELECT * FROM users WHERE id = :id1", array(':id1' => $idnrr)); if ($users->count()) { foreach ($users->results() as $result) { echo $result->name . "<br />"; } } public function query($sql, $params) { $this->_error = false; if ($this->_query = $this->_pdo->prepare($sql)) { $x = 1; if ($this->_query->execute($params)) { $this->_results = $this->_query->fetchAll(PDO::FETCH_OBJ); $this->_count = $this->_query->rowCount(); } else { $this->_error = true; } } return $this; } I dont no if this should even go here but here it goes. I created a blog were each blog post is veiwed on the same page in regards to the id passed to it (as standard). What i really need to do is incorporate the facebook comment box onto the page but... it only relates to the document itself rather than it's dynamic content. I have a comment form that I have created. It gets the id from the database and prints out the data that goes with that id, but what it also does is prints out the information into the form. I want a blank form so that the user can add a comment to the record. Any ideas? This the code for the form: Code: [Select] <form method="post" action="pv.php?id=<?php echo $row['ID']?>&action=<?php echo $form_action ?>"> <fieldset> <legend></legend> <p> <label for="cname">Date Of Birth</label> * <input id="cname" name="dateofbirth" class="required date" value="<?php echo $row['Date_Of_Birth']?>" /> (eg 1978.11.11) </p> <p> <label for="cgender">Gender</label> * <input type="radio" name="gender" value="Male" <?php if($row['Gender']=='male'){echo 'checked';}?>/> Male <input type="radio" name="gender" value="Female" <?php if($row['Gender']=='female'){echo 'checked';}?>/> Female </td> </p> <p> <label for="curl">Title</label> * <select name="title" id="title" class="required"> <option value="">Please Select</option> <option value="Mr" <?php if($row['Title']=='Mr'){echo 'selected';}?>>Mr</option> <option value="Ms" <?php if($row['Title']=='Ms'){echo 'selected';}?>>Ms</option> <option value="Mrs" <?php if($row['Title']=='Mrs'){echo 'selected';}?>>Mrs</option> <option value="Miss" <?php if($row['Title']=='Miss'){echo 'selected';}?>>Miss</option> <option value="Other" <?php if($row['Title']=='Other'){echo 'selected';}?>>Other</option> </select> </p> <p> <label for="ccomment">First Name</label> * <input type="text" name="firstname" value="<?php echo $row['First_Name']?>" maxlength="50" /> </p> <p> <label for="cemail">Last Name</label> * <input id="cemail" type="text" name="lastname" value="<?php echo $row['Last_Name']?>" maxlength="75" /> </p> <p> <label for="ccomment">Address 1</label>* <input type="text" name="address1" value="<?php echo $row['Address_Line_1']?>" maxlength="50" /> </p> <p> <label for="ccomment">Address 2</label> <input type="text" name="address2" value="<?php echo $row['Address_Line_2']?>" maxlength="50" /> </p> <p> <label for="ccomment">City</label>* <input type="text" name="city" value="<?php echo $row['City']?>" maxlength="50" /> </p> <p> <label for="ccomment">Postcode</label>* <input type="text" name="postcode" value="<?php echo $row['Postcode']?>" maxlength= "10" /> (eg LE5 5QE) </p> <p> <label for="ccomment">Contact No</label>* <input type="text" name="contactno" value="<?php echo $row['Contact_No']?>" maxlength= "12" /> (eg 077448825723) </p> <p> <label for="ccomment">Email</label>* <input type="text" name="email" value="<?php echo $row['Email']?>" maxlength= "40"/> (eg info@example.com) </p> <p> <label for="ccomment">Comment</label> <textarea rows="10" cols="30" name="note" maxlength= "500"><?php echo $row['Additional_Comment']?></textarea> </p> <p> <input class="submit" type="submit" value="Submit"/> </p> <p> <a href='pv.php'>Main Page</a> </p> </fieldset> This is the code for printing out the data on the page: Code: [Select] if($_GET['action']=='comment'){ $form_action = 'comment_ok'; $id=$_GET['id']; $result = mysql_query("SELECT * FROM project_data WHERE id='$id'"); $row = mysql_fetch_array($result); echo'<b>'; echo $row['Date_Of_Birth']; echo '  '; echo $row['Gender']; echo '  '; echo $row['Title']; echo '  '; echo $row['First_Name']; echo '  '; echo $row['Last_Name']; echo '  '; echo $row['Address_Line_1']; echo '  '; echo $row['Address_Line_2']; echo '  '; echo $row['City']; echo '  '; echo $row['Postcode']; echo '  '; echo $row['Contact_No']; echo '  '; echo $row['Email']; echo '  '; echo $row['Additional_Comment']; echo '</b>'; } and a snippet of the code I am using to send the id to the form: Code: [Select] echo "<td><a href='pv.php?action=edit&id=" . $row['ID']."'>Edit</a>  <a href='pv.php?action=delete_ok&id=" . $row['ID']."'>Delete</a>  <a href='pv.php?action=comment&id=" . $row['ID']."'>Comment</a></td>"; echo "</tr>"; |