Jump to content

kleb

Members
  • Posts

    78
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

kleb's Achievements

Member

Member (2/5)

0

Reputation

  1. wow!! dont border i have fixed it.thanks everyone for your concern
  2. i just changed it now.i put the insert before the select but i noticed that if i donot insert any data the ones already in the database table will not be showed
  3. thanks guys i think i will just that now
  4. please help me with this.since i started posting this form to its self it has been inserting values twice into the database when the user clicks submit button and i also noticed that i have to refresh the page before inserted comments can be showed.this is my code: <?php include"header.php"; $sql="SELECT post_content,post_by FROM post WHERE topicsID='$tpid'"; $result=mysql_query($sql)or die(mysql_error()); while($row=mysql_fetch_array($result)) { echo"<strong>{$row['post_by']}</strong>: {$row['post_content']}"."</br>"; } ?></td> </tr> </table> <?php include"header.php"; if(isset($_POST['submit'])) { $comment=mysql_real_escape_string(trim($_POST['comment'])); $name=mysql_real_escape_string(trim($_POST['name'])); $hidden=$_POST['id']; if($comment!=='' && $name!=='') { $topicid=$_GET['id']; $ins="INSERT INTO post(post_content,post_by,post_id)VALUES('$comment','$name','$topicid')"; mysql_query($ins) or die(mysql_error()); } else { echo"you cannot post an empty field"; } } ?> <h3>Post your comments here</h3> <form action=''method='post'> <textarea name="comment" id="content" style="width:400px;height:50px;background-color:#D0F18F;color:#000000;font:15px/20px cursive;scrollbar-base-color:#638E0D;"></textarea> <br /> Name:<input type="text"name="name"/> <input class="button" type="submit"name="submit"value="submit" /> </p> </form>
  5. am so confused i dont even understand again what you are all saying :'(
  6. @adam this is how my table looks like <?php $db_name="****"; $db_user="****"; $db_pass="****"; $con=mysql_connect('localhost',$db_user,$db_pass) or die(mysql_error()); mysql_select_db($db_name); $user="CREATE TABLE IF NOT EXISTS user( userID int( not null auto_increment, primary key(userID), user_name varchar(50) not null,user_email varchar(20) not null,user_password varchar(30) not null,user_date TIMESTAMP not null,UNIQUE INDEX email_unique(user_email))"; mysql_query($user); $topic="CREATE TABLE IF NOT EXISTS topics(topicsID int( not null AUTO_INCREMENT,primary key(topicsID),topics_subject varchar (200) ,topics_content text not null,topics_date TIMESTAMP not null, topics_cat varchar(20) not null, topics_by varchar(100) not null)"; mysql_query($topic) or die(mysql_error()); $post="CREATE TABLE IF NOT EXISTS post(topicsID int( not null AUTO_INCREMENT,primary key(topicsID),post_content text not null,post_by varchar(100) not null)"; mysql_query($post); $edit="CREATE TABLE IF NOT EXISTS editorial(editorialID int( not null AUTO_INCREMENT,PRIMARY KEY(editorialID),editorial_content text not null,editorial_by varchar(100) not null)"; mysql_query($edit) or die(mysql_error()); ?>
  7. at akay7 it gave me an error:Duplicate entry '2' for key 'PRIMARY'
  8. this is the code: <?php include"header.php"; if(isset($_POST['submit'])) { $comment=mysql_real_escape_string(trim($_POST['comment'])); $name=mysql_real_escape_string(trim($_POST['name'])); $hidden=$_POST['id']; if($comment!=='' && $name!=='') { $ins="UPDATE post(topicsID,post_content,post_by)VALUES('$hidden','$comment','$name')"; mysql_query($ins) or die(mysql_error()); } else { echo"you cannot post an empty field"; } } ?> <h3>Post your comments here</h3> <form action=''method='post'> <textarea name="comment" id="content" style="width:400px;height:50px;background-color:#D0F18F;color:#000000;font:15px/20px cursive;scrollbar-base-color:#638E0D;"></textarea> <br /> Name:<input type="text"name="name"/> <input class="button" type="submit"name="submit"value="submit" /> <input type="hidden"name="id"value='<?php echo "$tpid"; ?>'/> </p> </form>
  9. please am still new in php. i wanted to insert new records into a column(am working on a comment page)but when i used INSERT it gave me duplicate key error but i was advised to use UPDATE but it also said that i have a syntax error.please how do i use the UPDATE because what i did was i just cleaned the INSERT and wrote UPDATE. thanks
  10. The primary key is the topics ID this started when i tried to insert the id from the hidden field into the post table.please note that i joined TOPIC TABLE AND POST TABLE with a common id i named topicsID
  11. although the codes here may look familiar but its a new thread! have being working on my codes and posting problems any time i run into it what i want to do is to be able to display comments made on any topic by the user and i ran into this problem
  12. Please i ran into this problem help me : <p>Posted by <a href=""> <?php if(isset($_GET['id'])) { $tpid=$_GET['id']; } else { $tpid=$_POST['id']; } include"header.php"; $sql="SELECT*FROM topics WHERE topicsid='$tpid'"; $result=mysql_query($sql) or die(mysql_error()); while($row=mysql_fetch_array($result)) { echo"{$row['topics_by']}"; echo"</a></p>"; echo"<p>"; echo"{$row['topics_subject']}"; echo" <p align='left'><img src='speakout_1.png'/>"; echo"{$row['topics_content']}"; echo"<p class='post-footer align-right'> <a href='' class='comments'>"; session_start(); if(isset($_SESSION['views'])) $_SESSION['views']=$_SESSION['views']+1; else $_SESSION['views']=1; echo"Comments:".$_SESSION['views']; echo"</a>"; echo"<span class='date'>"; echo"{$row['topics_date']}"; } ?></span> </p> </div> <h3>Comments:</h3> <table> <tr class="row-a"> <td class="first"></td> <td><?php include"header.php"; $sql="SELECT post_content,post_by FROM post WHERE topicsID='$tpid'"; $result=mysql_query($sql)or die(mysql_error()); while($row=mysql_fetch_array($result)) { echo"<strong>{$row['post_by']}</strong>: {$row['post_content']}"."</br>"; } ?></td> </tr> </table> <?php include"header.php"; if(isset($_POST['submit'])) { $comment=mysql_real_escape_string(trim($_POST['comment'])); $name=mysql_real_escape_string(trim($_POST['name'])); $hidden=$_POST['id']; if($comment!=='' && $name!=='') { $ins="INSERT INTO post(topicsID,post_content,post_by)VALUES('$hidden','$comment','$name')"; mysql_query($ins) or die(mysql_error()); } else { echo"you cannot post an empty field"; } } ?> <h3>Post your comments here</h3> <form action=''method='post'> <textarea name="comment" id="content" style="width:400px;height:50px;background-color:#D0F18F;color:#000000;font:15px/20px cursive;scrollbar-base-color:#638E0D;"></textarea> <br /> Name:<input type="text"name="name"/> <input class="button" type="submit"name="submit"value="submit" /> <input type="hidden"name="id"value='<?php echo "$tpid"; ?>'/> </p> </form> <br /> </div>
  13. am still confused.ok i will try to remove some of the codes
  14. this is what i want to do: i want users to beable to comment on any topic that was created by other users which i have succesfully done but the problem i have is that when a new visitor clicks on the topics it just display all the content in the post table where the comments are inserted..i.e if i have topic(a) topic(b) and topic© and a user comments on topic© and i click on the topic© to view the comments it will not only show comment made on topic© but all the comments made on topic(a) and topic(b) on topic© page like wise if you click on topic(a) and topic(b) and any topics created further. this is my code:this is the page where the topics are created <h3>Topics</h3> <table> <tr> <th class="first"><strong>Category </strong></th> <th>Topic</th> <th>Post date</th> </tr> <tr class="row-a"> <td class="first"><?php include"header.php"; $sql="SELECT *FROM topics"; $result=mysql_query($sql) or die(mysql_error()); while($row=mysql_fetch_array($result)) { echo"{$row['topics_cat']}"."</br>"; } ?></td> <td><?php include"header.php"; $sql="SELECT *FROM topics "; $result=mysql_query($sql)or die(mysql_error()); while($row=mysql_fetch_array($result)) { echo"<a href='comment.php?id={$row['topicsID']}'>{$row['topics_subject']}</a>"."</br>"; } ?></td> <td><?php include"header.php"; $sql="SELECT* FROM topics"; $result=mysql_query($sql) or die(mysql_error()); while($row=mysql_fetch_array($result)) { echo"{$row['topics_date']}"."</br>"; } ?></td> </tr> </table> <h3>Post your topic here</h3> <form action='topic.php'method='post'> <label>Note:your write up should not be more than 200 words.thanks</label> Topic:<input type="text"name="topic"value="your topic goes here" /></br> Category:<input type="text"name="cat"value="E.g Politics,Sports.etc"/></br> Name:<input type="text"name="name"value="your name"/> <textarea name="content" id="content" style="width:300px;height:50px;background-color:#D0F18F;color:#000000;font:15px/20px cursive;scrollbar-base-color:#638E0D;">Your comment goes here.</textarea> <br /> <input class="button" type="submit"name="submit"value="submit" /> </p> </form> <blockquote>Please note that we welcome would-be person(s) that wish to write on our Editorial board from any part of the world.</br> If you are intrested kindly send your write up not more than 350 words with your personal photo and any image related to your article and forward it to Email:editorial@planetafric.com</br>Thanks so much.</blockquote> [code] this is the page that handles the topics <?php include"header.php"; if(isset($_POST['submit'])) { $topic=mysql_real_escape_string(trim($_POST['topic'])); $cat=mysql_real_escape_string(trim($_POST['cat'])); $by=mysql_real_escape_string(trim($_POST['name'])); $content=mysql_real_escape_string(trim($_POST['content'])); $dateTime = new DateTime("now", new DateTimeZone('GMT')); $date =$dateTime->format("Y-m-d H:i:s"); if($topic!=='' && $cat!=='' && $by!=='' && $content!=='') { $ins="INSERT INTO topics(topics_subject,topics_content,topics_cat,topics_date,topics_by)VALUES('$topic','$content','$cat','$date','$by')"; $inss=mysql_query($ins) or die(mysql_error()); if($inss) { echo "Your topic as been inserted<a href='page.php'> click here to view your topic(s)</a>"; } else { echo"There was a problem inserting your records please try again"; } } else { echo"You can not leave any field blank, please fill all fields"; } } ?> [/code] this is the page where comments are made: <p>Posted by <a href=""><?php include"header.php"; $topicid=$_GET['id']; $sql="SELECT*FROM topics WHERE topicsID=$topicid"; $result=mysql_query($sql) or die(mysql_error()); while($row=mysql_fetch_array($result)) { echo"{$row['topics_by']}"; } ?></a></p> <p><?php include"header.php"; $topicid=$_GET['id']; $sql="SELECT*FROM topics WHERE topicsID=$topicid"; $result=mysql_query($sql) or die(mysql_error()); while($row=mysql_fetch_array($result)) { echo"{$row['topics_subject']}"; } ?> <p align="left"><img src="speakout_1.png"/> <?php include"header.php"; $topicid=$_GET['id']; $sql="SELECT*FROM topics WHERE topicsID=$topicid"; $result=mysql_query($sql) or die(mysql_error()); while($row=mysql_fetch_array($result)) { echo"{$row['topics_content']}"; } ?> <p class="post-footer align-right"> <a href="" class="comments"><?php session_start(); if(isset($_SESSION['views'])) $_SESSION['views']=$_SESSION['views']+1; else $_SESSION['views']=1; echo"Comments:".$_SESSION['views']; ?></a> <span class="date"><?php include"header.php"; $topicid=$_GET['id']; $sql="SELECT*FROM topics WHERE topicsID=$topicid"; $result=mysql_query($sql) or die(mysql_error()); while($row=mysql_fetch_array($result)) { echo"{$row['topics_date']}"; } ?></span> </p> </div> <h3>Comments:</h3> <table> <tr class="row-a"> <td class="first"></td> <td><?php include"header.php"; $sql="SELECT post_content,post_by FROM post ORDER BY topicsID"; $result=mysql_query($sql)or die(mysql_error()); while($row=mysql_fetch_array($result)) { echo"<strong>{$row['post_by']}</strong>: {$row['post_content']}"."</br>"; } if(mysql_affected_rows()>0) { header("location:".$_SERVER['PHP_SELF']); } ?></td> </tr> </table> <h3>Post your comments here</h3> <form action='reply.php'method='post'> <textarea name="comment" id="content" style="width:400px;height:50px;background-color:#D0F18F;color:#000000;font:15px/20px cursive;scrollbar-base-color:#638E0D;"></textarea> <br /> Name:<input type="text"name="name"/> <input class="button" type="submit"name="submit"value="submit" /> </p> </form> <br /> </div> this is the code that handles the comments: <?php include"header.php"; if(isset($_POST['submit'])) { $comment=mysql_real_escape_string(trim($_POST['comment'])); $name=mysql_real_escape_string(trim($_POST['name'])); if($comment!=='' && $name!=='') { $ins="INSERT INTO post(post_content,post_by)VALUES('$comment','$name')"; mysql_query($ins) or die(mysql_error()); else { echo"You can not post an empty page or leave your name blank"; } } } ?>
  15. am having problem with showing specific comments on a specific topic created by users please visit the site:www.planetafric.com and click on the topics you will understand what am trying to say.i will post the code later but i want you to visit the site in other for you to understand what am trying to say .You will discover that the comment made on a topic(a) shows in topic(b) also which is not supposed to be so thanks so much
×
×
  • 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.