Shout Box Help

Pages: 1, 2
free web hosting

Read Latest Entries..: (Post #19) by KansukeKojima on Apr 1 2008, 08:21 PM. (Line Breaks Removed)
Err... yeah wait... I'll try out what you said in your previous post...*EDIT* Ok, I did what you suggested in the previous post. Works like a charm! Thank you so much!!feel free to test it outhttp://2kart.trap17.com (click the 'Open Shoutbox Window' link)EDIT 2bbcode is now included.... read more.
Read the FIRST post of this Topic. - Express your Opinion! Contribute Knowledge :-).

Open Discussion > CONTRIBUTE > Computers > Database

Shout Box Help

KansukeKojima
Alright... so this is really my first time using databases at all. Anyways, I need some help.

http://2kart.trap17.com/shoutbox.php

I used a tutorial from spoono.com (http://www.spoono.com/php/tutorials/tutorial.php?id=19) to create this... everything seems to work, except that it won't show what is posted in the shoutbox.....

my code is below.... and since I hardly know anything about databases, I'm sure you'll find an error quickly.

Thanks!

CODE
<?php
//host name password
mysql_connect("localhost","name","password");

//select database
mysql_select_db("shoutboxdatabase");

if($submit)
{
//date function
$time=date ("h:ia d/j/y");

//insert into shoutbox table
$result=MYSQL_QUERY("INSERT INTO shoutbox (id,name,message,time)".
"VALUES ('NULL','$name', '$message','$time')");
}

//last five messages
$result = mysql_query("select * from shoutbox order by id desc limit 5");

//while loop
while($r=mysql_fetch_array($result))
{
//variables from table
$time=$r["time"];
$id=$r["id"];
$message=$r["message"];
$name=$r["name"];
?>

<?php  $time ?><br />
<?php echo $name ?><br />
<?php echo $message ?><br />
<?php } ?>
<form action="<?php echo $php_self ?>" method="post">
<INPUT TYPE='TEXT' value='Name' NAME='name' SIZE=30 maxlength='100'><br />
<INPUT TYPE='TEXT' value='Message' NAME='message' size=30 maxlength='100'>
<input type="submit" name="submit" value="Submit">
</form>


 

 

 


Reply

shadowx
The first thing i notice is this line:

QUOTE
mysql_select_db("shoutboxdatabase");


Is this how it is in the code or have you changed the DB name to hide it?

The reason i ask is that with T17 you need to prefix the DB name with your hosting username EG: If my cpanel login name was "shadowx" (which it isnt by the way...) My DB name would be "shadowx_shoutboxdatabase"

I dont have time to look through the code so if this isnt the problem someone else will have to help!

Reply

KansukeKojima
yeah... just never mind all the db connect stuff... I changed it to hide the info....

Reply

sonesay
Either check through cpanel if entries are being inserted into the database using myphpadmin or what ever its called. Then if entries are being inserted there check your actually receiving results from the query by using
CODE
$found = mysql_num_rows($result);
echo $found;


if your getting the correct return entries then we can assume its correct and the error is on the loop where you try and output the results. How you have done it I never do
CODE
while($r=mysql_fetch_array($result))
{
//variables from table
$time=$r["time"];
$id=$r["id"];
$message=$r["message"];
$name=$r["name"];
?>

<?php $time ?><br />
<?php echo $name ?><br />
<?php echo $message ?><br />
<?php } ?>


CODE
while($r=mysql_fetch_array($result))
{
//variables from table
$time=$r["time"];
$id=$r["id"];
$message=$r["message"];
$name=$r["name"];

echo $time."<br />";
echo $name."<br />";
echo $message."<br />";
}

?>

I would just keep the while loop in side the same php tags. I dont know what the effect of it doing your way does but obviously it did not pick up the error when you tried to just do "$time" with no echo biggrin.gif. just try it this way and see if it works.


 

 

 


Reply

jlhaslip
Can you get results from the Database using this Query in the phpMyAdmin using the SQL function?
CODE
select * from shoutbox order by id desc limit 5"


Also, add this after the query in your script to see what the script is getting for results:
CODE
print_r( $result );


Of course, set error reporting at the top of the script to see if the script is tossing an error:
CODE
ini_set("display_errors", 1);
error_reporting(E_ALL);

Reply

KansukeKojima
I think that this may be it.
QUOTE
Notice: Undefined variable: submit in /home/kansuke/public_html/shoutbox.php on line 11
Resource id #3

... what is the undefined variable in the code?

and it rejects the query you said to use...

Reply

sonesay
you didnt say if that was your entire code you posted. Looking at it now $submit is not defined as when its submitted your checking if($submit

refer to it as $_POST['submit'];

Reply

truefusion
A couple of suggestions:

Replace:
CODE
while($r=mysql_fetch_array($result))
{
//variables from table
$time=$r["time"];
$id=$r["id"];
$message=$r["message"];
$name=$r["name"];
?>

<?php  $time ?><br />
<?php echo $name ?><br />
<?php echo $message ?><br />
<?php } ?>

With:
CODE
while($r=mysql_fetch_assoc($result)){
//variables from table
echo $r["time"]."<br/>\n".$r["id"]."<br/>\n".$r["name"].":<br/>\n".$r["message"]."<br/>\n";
}
?>

to save some space, and to receive an associative array from the result.

And since the form is going to be submitted to the same page it's in, you can have simply this:
HTML
<form action="" method="post">

Reply

electriic ink
Also, your output code reads this:

CODE
<br />
<b>Notice</b>: Undefined variable: submit in <b>/home/kansuke/public_html/shoutbox.php</b> on line <b>11</b><br />
Resource id #3<form action="<br />
<b>Notice</b>: Undefined variable: php_self in <b>/home/kansuke/public_html/shoutbox.php</b> on line <b>37</b>
<br />
" method="post">
<INPUT TYPE='TEXT' value='name' NAME='name' SIZE=30 maxlength='100' /><br />
<INPUT TYPE='TEXT' value='message' NAME='message' SIZE=30 maxlength='100' /><br />
<input type="submit" name="submit" value="submit">
</form>


The error is on the following line in the source code:

CODE
<form action="<?php echo $php_self ?>" method="post">


Which should read:

CODE
<form action="<?php echo $SERVER['PHP_SELF']; ?>" method="post">



Reply

KansukeKojima
QUOTE(sonesay @ Mar 28 2008, 05:23 PM) *
you didnt say if that was your entire code you posted. Looking at it now $submit is not defined as when its submitted your checking if($submit

refer to it as $_POST['submit'];


I think that would maybe solve it... but, where am I supposed to place it? I'm not quite clear on where you want me to place $_POST['submit'].

Reply

Latest Entries

KansukeKojima
Err... yeah wait... I'll try out what you said in your previous post...

*EDIT*

Ok, I did what you suggested in the previous post. Works like a charm! Thank you so much!!

feel free to test it out

http://2kart.trap17.com (click the 'Open Shoutbox Window' link)

EDIT 2

bbcode is now included.

Reply

sonesay
if you really need to do it on the same page and not like how I said previous post with submitting to another page then redirecting back to the original. that way save post variables are lost then..

You can probably do it with some javascript. Set a flag for when the submit button is acutally pressed. That way you can distinguish between page reloads and real submissions. I wont give you exact code but that is the idea. Have a onclick function on your button to set flag that it is a real submit then check on your if statement code. If you really need the exact logic and code reply lol.

Reply

KansukeKojima
Thanks jlhaslip, I tried what you posted unfortuneately, it does not work. But, I've found something that does, and unless someone can come up with a better method... <iframes>!

Fortuneately, it keeps the shoutbox from re-posting... so I'll probably be using them... unfortuneately xD...

If someone has a better idea...I'll use it.

Reply

jlhaslip
Does this work any better?
I have adjusted it a little so that it checks to see if the Form is 'set' before assigning the variables used.
CODE
<?
ini_set("display_errors", 1);
error_reporting(E_ALL);
//the host, name, and password for your mysql
mysql_connect("localhost","not tellin you!","not tellin");

//select the database
mysql_select_db("not tellin");
if(isset($_POST['submit']))
{
    $submit = $_POST['submit'];
    $name = $_POST['name'];
    $message = $_POST['message'];

//use the PHP date function for the time
   $time=date("h:ia d/j/y");
  
   // inserting it into the shoutbox table which we made in the mysql statements before
   $result=MYSQL_QUERY("INSERT INTO shoutbox (id,name,message,time)".
      "VALUES ('NULL','$name', '$message','$time')");
}
?>
<?
//returning the last 5 messages
$result = mysql_query("select * from shoutbox order by id desc limit 5");

//the while loop
while($r=mysql_fetch_assoc($result)){
//variables from table
echo $r["time"]."<br/>\n".$r["id"]."<br/>\n".$r["name"].":<br/>\n".$r["message"]."<br/>\n";
}
?>
<form action="" method="post">
<INPUT TYPE='TEXT' value='name' NAME='name' SIZE=30 maxlength='100' /><br />
<INPUT TYPE='TEXT' value='message' NAME='message' SIZE=30 maxlength='100' /><br />
<input type="submit" name="submit" value="submit">
</form>

Reply

sonesay
The reason why its keeps reposting is because the post variable are saved since its posted to the same page. When you reload you reload the post lol. The only other way to do it so you can reload that page without double posting is to have it submit to a page thats designed specifically for inserting in to the database. Then redirect it back to the original page where you display form and last previous five message. I'm pretty sure that will work so you need an extra php page.

I dont think its possible to destroy post variables after a post. I could be wrong but I dont think we have acess to anything like that.. doubt it lol.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Pages: 1, 2
Recent Queries:-
  1. php "destroy post variables" - 58.78 hr back. (1)
Similar Topics
Looking for shout, box

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for shout, box

*MORE FROM TRAP17.COM*
advertisement



Shout Box Help



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE