Jump to content

comment box


runnerjp

Recommended Posts

hey guys i have done this for a comment box on my website

 

<?php session_start();
{	// Sign the guestbook
require_once("../settings.php");
       
       $id = $_SESSION['user_id'];  

$get_username_value = get_username($id);

$username = $_GET['user'];
$from = $get_username_value;
$message = $_POST["message"];
$time = date("F j, Y, g:i a"); 
$db = new DbConnector();
$db->connect();
$query = "INSERT INTO guestbook(owner,postedby,post,time) VALUES('$username','$from','$message','$time')";
$db->query($query);
echo "Your message has been posted";

}

$owner = $get_username_value;
$query = "SELECT * FROM guestbook WHERE owner= $get_username_value ORDER BY ID DESC";
$result = $db->query($query);
while($gbrows = mysql_fetch_array($result))
{
	echo "Posted by: <a href=\"member.php?id=".$gbrows["postedby"]."\">".$gbrows["postedby"]."</a> - ".$gbrows["time"]."<br/>".$gbrows["post"]."<br><br>";
}
echo "<center><br/><b>Sign $owner:s guestbook</b><br/>
<form action=\"member.php?sign=$owner&from=$get_username_value method='POST'>
<textarea name='message' rows='5' cols='30' align='left'>Your message</textarea><br/>
<input type='submit' value='Update' name='submit'>
</form>
</center>
		";?>

 

but i just get a blank page... any reason why?>

Link to comment
Share on other sites

for this

 

    $id = $_SESSION['user_id']; 

 

$get_username_value = get_username($id);

 

$username = $_GET['user'];

$from = $get_username_value;

$message = $_POST["message"];

$time = date("F j, Y, g:i a");

$db = new DbConnector();

$db->connect();

$query = "INSERT INTO guestbook(owner,postedby,post,time) VALUES('$username','$from','$message','$time')";

$db->query($query);

echo "Your message has been posted";

 

as its different to the rest of code

Link to comment
Share on other sites

i think plz check this function get_username($id)

 

and  what is the value of $username,$from and $owner; all are same or different.

 

becouse u insert value in database owner is $username and when fetch then u use owner=$owner

 

and here

 

action=\"member.php?sign=$owner&from=$get_username_value both sign and $get_username_value are same i think

 

 

Link to comment
Share on other sites

Try to echo $get_username_value, $username and the other variables to see if ure getting any values. Place an "or die(mysql_error())" after the query to check if theres any possible error in it. Check if the session has got a value.

 

And if $get_username_value isnt an int, the following query

 

$query = "SELECT * FROM guestbook WHERE owner= $get_username_value ORDER BY ID DESC";

 

should be (added single quotes in $get_username_value):

 

$query = "SELECT * FROM guestbook WHERE owner='$get_username_value' ORDER BY ID DESC";

Link to comment
Share on other sites

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/runningp/public_html/members/include/box.php on line 25

 

<?php session_start();
// Sign the guestbook
require_once("../settings.php");
    {
       $id = $_SESSION['user_id'];  

$get_username_value = get_username($id);

$username = $_GET['user'];
$from = $get_username_value;

$message = $_POST["message"];
$time = date("F j, Y, g:i a");
$query = "INSERT INTO guestbook(owner,postedby,post,time) VALUES('$username','$from','$message','$time')";
$db->query($query);
echo "Your message has been posted";



}

$owner = $get_username_value;
$query = $query = "SELECT * FROM guestbook WHERE owner='$get_username_value' ORDER BY ID DESC"; 
$result = $db->query($query);
while($grab = mysql_fetch_array($result))
{
	echo "Posted by: <a href=\"member.php?id=".$grab["postedby"]."\">".$grab["postedby"]."</a> - ".$grab["time"]."<br/>".$grab["post"]."<br><br>";
}
echo "<center><br/><b>Sign $owner:s guestbook</b><br/>
<form action=\"member.php?sign=$owner&from=$get_username_value method='POST'>
<textarea name='message' rows='5' cols='30' align='left'>Your message</textarea><br/>
<input type='submit' value='Update' name='submit'>
</form>
</center>";

?>

 

basicly i cant undestand whats up with while($grab = mysql_fetch_array($result))

{

echo "Posted by: <a href=\"member.php?id=".$grab["postedby"]."\">".$grab["postedby"]."</a> - ".$grab["time"]."<br/>".$grab["post"]."<br><br>";

} to fetch all the results for the comment area

 

 

also if there is an easyer way of making a comment box for each profile im open to suggestions lol but this is the way iv thought about going about it

Link to comment
Share on other sites

ok atting at from scratch and i have got an error im not famillia with

 

<?php
session_start(); // starts sessions

$id = $_SESSION['user_id'];
$query = "SELECT * FROM guestbook WHERE id = '$id' LIMIT 1"; 
if ($result = mysql_query($query)){
    if (mysql_num_rows($result)) {
        $array = mysql_fetch_assoc($result);
       		$message = $array['message'];
       		}}



echo $message; 


echo (" <form method='POST' action='?page=updatepost'>
<table width="523" border="0" align="center" cellpadding="0" cellspacing="2">
<tr><td width="150"><div align="right">
<label for="events">Message</label>
</div>
</td>
<td colspan="2"><textarea class="input" id="message" name="message" rows="4" cols="40">type your message here</textarea></td>
</tr>
<tr>
<td width="150"></td>
<td width="112"><input name="submitButtonName" type="submit" class="submit-btn" value=""></td>
<td width="253"> </td>
</tr>
</table>
</form>");
case 'updatepost':
$id = $_POST['id'];
$message = $_POST['message'];
$update = "INSERT guestbook SET message='$message', id = '$id' WHERE id='$id' ";
$rsUpdate = mysql_query($update);
if ($rsUpdate)?>

 

unexpected T_LNUMBER on this line <table width="523" border="0" align="center" cellpadding="0" cellspacing="2">

Link to comment
Share on other sites

Replace all that with this..

 

<?php
session_start(); // starts sessions

$id = $_SESSION['user_id'];
$query = "SELECT * FROM guestbook WHERE id = '$id' LIMIT 1"; 
if ($result = mysql_query($query)){
   if (mysql_num_rows($result)) {
       $array = mysql_fetch_assoc($result);
      		$message = $array['message'];
      		}}



echo $message; 


echo (' <form method="POST" action="?page=updatepost">
<table width="523" border="0" align="center" cellpadding="0" cellspacing="2">
<tr><td width="150"><div align="right">
<label for="events">Message</label>
</div>
</td>
<td colspan="2"><textarea class="input" id="message" name="message" rows="4" cols="40">type your message here</textarea></td>
</tr>
<tr>
<td width="150"></td>
<td width="112"><input name="submitButtonName" type="submit" class="submit-btn" value=""></td>
<td width="253"> </td>
</tr>
</table>
</form>');

case 'updatepost':
$id = $_POST['id'];
$message = $_POST['message'];
$update = "INSERT guestbook SET message='$message', id = '$id' WHERE id='$id' ";
$rsUpdate = mysql_query($update);
if ($rsUpdate)?>

 

All your HTML wasnt getting sent out..  if you look at your syntax highlighting shown here, everything in blue was not encapsilated..  It's been a long time since ive had to echo out HTML so if my code doesnt work change the first and last ' to " then everything in between to ' and it should work...  if your syntax is right it should ALL be red inside the entire echo.

Link to comment
Share on other sites


humm i dont think im using my switch statement properly

 

<?php
session_start(); // starts sessions

$id = $_SESSION['user_id'];
$query = "SELECT * FROM guestbook WHERE id = '$id' LIMIT 1"; 
if ($result = mysql_query($query)){
    if (mysql_num_rows($result)) {
        $array = mysql_fetch_assoc($result);
       		$message = $array['message'];
       		



echo $message; 

{switch($_GET

)}
default:
echo (' <form method="POST" action="?page=updatepost">
<table width="523" border="0" align="center" cellpadding="0" cellspacing="2">
<tr><td width="150"><div align="right">
<label for="events">Message</label>
</div>
</td>
<td colspan="2"><textarea class="input" id="message" name="message" rows="4" cols="40">type your message here</textarea></td>
</tr>
<tr>
<td width="150"></td>
<td width="112"><input name="submitButtonName" type="submit" class="submit-btn" value=""></td>
<td width="253"> </td>
</tr>
</table>
</form>');

case 'updatepost':
$id = $_POST['id'];
$message = $_POST['message'];
$update = "INSERT guestbook SET message='$message', id = '$id' WHERE id='$id' ";
$rsUpdate = mysql_query($update);
if ($rsUpdate)}}?>

 

also im missing some {} out sum where but for the life of me can see where abouts

Link to comment
Share on other sites

ok i have progressed alot so far :P

 

but for some reaosn my code will not add the users username.. it leaves the field blank

 

<html>
<head>
<title>Shoutbox!</title>
<style type="text/css">
<!--
.message {
color: #000000;
font-family: Verdana;
font-size: 10px;}

.username {
color: #FF9900
font-family: Verdana;
font-size: 10px;
font-weight: bold}

.date {
color: #707070;
font-family: Verdana;
font-size: 9px;}

.forms {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10 px;
color: #6CA05A;
text-decoration: none;
background-color: #CCCCCC;
border-color: #6CA05A;
border-style: solid;
border: 1px}

.submit {
background-color: #CCCCCC;
border-color: #6CA05A;
color: #2A343C;
font-family: Verdana;
font-size: 10px;
border-style: solid;
border 1 px;}
-->
</style>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" style="padding: 2px">
<?php

// If submitted
if($_POST['submit']) {

// Verify if the fields were filled.
if(!$_POST['message']) {
echo 'Error, You need to post a Message!';
die;
}

// Date format
$date = date("d/m/y"); // http://www.php.net/date

// Assign variables of the forms

$id = $_SESSION['user_id'];
$username = $id;
$message = $_POST['message'];
$ip = $_SERVER['REMOTE_ADDR'];

// Connect to the database
include('../../settings.php');

// Insert the info in the shoutbox table.
$query = "INSERT INTO shoutbox ( username, message, date, ip)
VALUES ('$username','$message','$date','$ip')";
mysql_query($query);
// close connection


// Show message to let them return to the shoutbox
?>
<div align="center">Thank you for submitting.<br>
Return to the <a href="shoutbox.php">shoutbox</a>!
<?php
// If NOT submitted
} else {




$query = "SELECT * FROM shoutbox ORDER BY id DESC LIMIT 10";
$result = mysql_query($query);
// Create a table
?>

<table width="100%" cellpadding="0" cellspacing="0" border="0">

<?
// Run a While loop for the rows
while($c = mysql_fetch_array($result))
{
?>
<tr>
<td>
<? echo $c[author] ?></a> says:
<div align="justify"><? echo $c[message] ?></div>
</td>
</tr>
<tr><td>on <? echo $c[date] ?>
<hr noshade="noshade" size="1" style="border-style: dashed" color="#000000" /></td></tr>
<? } ?>

</table>

<form method="post" action="box.php">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>Message :</td>
<td><input type="text" name="message" class="forms"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="Speak!" class="subtmit"></td>
</tr>
</table>
</form>

<?php } ?>

</body>
</html> 

 

also i was wondering.. whats th best way to go now with assigning each user their own chatbox ?? 

 

so on profile 1 it has chatbox 1 come up

on profile 2 it has chatbox 2 ect ect

Link to comment
Share on other sites

ok i have tried everything... the table updates everythin but username... and its set to username

 

i thought it was $id = $_SESSION['user_id'];

$username = $id;

 

but i even tried

 

$username = 'bob'; lol and it does not even record that :S

Link to comment
Share on other sites

sorry i had to re open because i found anouther little thing....

 

include('../../settings.php');
$id = $_SESSION['user_id'];
$username = get_username($id);
$user = $_GET['user'];
$message = $_POST['message'];
$ip = $_SERVER['REMOTE_ADDR'];



// Insert the info in the shoutbox table.
$query = "INSERT INTO shoutbox ( user, username, message, date, ip)
VALUES ('{$_GET[user]}','$username','$message','$date','$ip')"or die(mysql_error());
mysql_query($query);

 

ok so im using $_GET['user']; to get the username out of the url soo members/bob

i have used it before to set friends to be friends,,, but it does not seem to be working in this case ??

 

here is my htaccess to show you that user is in there...

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([^/.]+)/?$ members/index.php?page=profile&username=$1 

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.