Welcome Guest ( Log In | Register)



2 Pages V  < 1 2  
Reply to this topicStart new topic
> Shout Box Help
sonesay
post Mar 31 2008, 07:59 PM
Post #11


|||[ n00b King ]|||
*********

Group: [HOSTED]
Posts: 589
Joined: 20-June 07
From: Auckland
Member No.: 45,102



This whole block in your original code would never return true since its $submit is not defined in PHP yet.
CODE
if($submit)
{
...
}


So you can either change it so you define $submit before its used or just change $submit to $_POST['submit']; directly. Submit is coming from your button named 'submit'.

CODE
// this
$submit = $_POST['submit'];
if($submit)
{
..
}
// or this
if($_POST['submit'])
{
..
}
Go to the top of the page
 
+Quote Post
KansukeKojima
post Mar 31 2008, 08:39 PM
Post #12


Super Member
*********

Group: [HOSTED]
Posts: 398
Joined: 13-October 06
From: Alberta, Canada
Member No.: 31,584



w00t! It works.

sonesay, what you said worked perfectly! But, an error said that the name and message variables were not defined... I almost posted another message saying that it would not work, but I added $name = $_POST['name']; and $message = $_POST['message']; and now it works perfectly! Thank you everyone that helped!

Now I just have to work on some styling and stuff...

thanks!

**EDIT**
ahh... crap... ok one problem left... whenever someone visits the page... it re-posts the previous message...... hmm... how would I fix that....

here is my code again...

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");
$submit = $_POST['submit'];
$name = $_POST['name'];
$message = $_POST['message'];
if($submit)
{  
//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>


This post has been edited by KansukeKojima: Mar 31 2008, 08:41 PM
Go to the top of the page
 
+Quote Post
sonesay
post Mar 31 2008, 08:51 PM
Post #13


|||[ n00b King ]|||
*********

Group: [HOSTED]
Posts: 589
Joined: 20-June 07
From: Auckland
Member No.: 45,102



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");
$submit = $_POST['submit'];
$name = $_POST['name'];
$message = $_POST['message'];
if($submit)
{


I think whats causing the error reporting for the first time you come to the page is the upper block of code where it says error reporting etc. Its catching and displaying the error when post vars submit, name, and message are assigned but are null I'm guessing. I would try and remove the error reporting statements in the first two lines and test it out. I think that way you can still try and assign the post variables and if they are null which would be in the case where someone first loads the page it shouldn't report the error. Not sure if this is good practice but if someone has a better way please post.
Go to the top of the page
 
+Quote Post
KansukeKojima
post Mar 31 2008, 09:07 PM
Post #14


Super Member
*********

Group: [HOSTED]
Posts: 398
Joined: 13-October 06
From: Alberta, Canada
Member No.: 31,584



well... this is retarded... the error messages are gone now... but it keeps reposting the last message you typed whenever you refresh teh page.... what the hell...
Go to the top of the page
 
+Quote Post
coolcat50
post Mar 31 2008, 09:08 PM
Post #15


Super Member
*********

Group: [HOSTED]
Posts: 228
Joined: 5-October 07
From: Random Places
Member No.: 51,171
Spam Patrol



Um Kansuke try this.

CODE
<?


//the host, name, and password for your mysql
mysql_connect("localhost","not tellin you!","not tellin");

//select the database
mysql_select_db("not tellin");
$submit = $_POST['submit'];
$name = $_POST['name'];
$message = $_POST['message'];
if($submit)
{  
//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')");
   $_POST['submit'] = 0;
   $_POST['message'] = "";
   $_POST['name'] = "";
}
?>
<?
//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>


EDIT: Fixed BBCode

This post has been edited by coolcat50: Mar 31 2008, 09:09 PM
Go to the top of the page
 
+Quote Post
sonesay
post Apr 1 2008, 04:48 AM
Post #16


|||[ n00b King ]|||
*********

Group: [HOSTED]
Posts: 589
Joined: 20-June 07
From: Auckland
Member No.: 45,102



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.

This post has been edited by sonesay: Apr 1 2008, 07:25 AM
Go to the top of the page
 
+Quote Post
jlhaslip
post Apr 1 2008, 05:05 AM
Post #17


A computer once beat me at chess, but it was no match for me at kick boxing.
Group Icon

Group: [MODERATOR]
Posts: 3,740
Joined: 24-July 05
From: In Trouble Again... still?
Member No.: 9,787
Spam Patrol



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>
Go to the top of the page
 
+Quote Post
KansukeKojima
post Apr 1 2008, 06:35 PM
Post #18


Super Member
*********

Group: [HOSTED]
Posts: 398
Joined: 13-October 06
From: Alberta, Canada
Member No.: 31,584



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.
Go to the top of the page