|
|
|
|
![]() ![]() |
Mar 28 2008, 07:01 PM
Post
#1
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 412 Joined: 13-October 06 From: Alberta, Canada Member No.: 31,584 |
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> |
|
|
|
Mar 28 2008, 07:34 PM
Post
#2
|
|
|
A clever man learns from his own mistakes, a WISE man learns from those of OTHERS ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 883 Joined: 12-April 06 From: Essex, UK Member No.: 21,719 |
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! |
|
|
|
Mar 28 2008, 07:38 PM
Post
#3
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 412 Joined: 13-October 06 From: Alberta, Canada Member No.: 31,584 |
yeah... just never mind all the db connect stuff... I changed it to hide the info....
|
|
|
|
Mar 28 2008, 09:53 PM
Post
#4
|
|
|
|||[ n00b King ]||| ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 593 Joined: 20-June 07 From: Auckland Member No.: 45,102 |
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 |
|
|
|
Mar 28 2008, 11:06 PM
Post
#5
|
|
|
A computer once beat me at chess, but it was no match for me at kick boxing. ![]() Group: [MODERATOR] Posts: 3,749 Joined: 24-July 05 From: In Trouble Again... still? Member No.: 9,787 ![]() |
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); |
|
|
|
Mar 28 2008, 11:18 PM
Post
#6
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 412 Joined: 13-October 06 From: Alberta, Canada Member No.: 31,584 |
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... This post has been edited by KansukeKojima: Mar 28 2008, 11:24 PM |
|
|
|
Mar 28 2008, 11:23 PM
Post
#7
|
|
|
|||[ n00b King ]||| ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 593 Joined: 20-June 07 From: Auckland Member No.: 45,102 |
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']; |
|
|
|
Mar 29 2008, 03:13 AM
Post
#8
|
|
|
Converting one Penguin at a time. ![]() Group: [MODERATOR] Posts: 1,741 Joined: 22-June 05 From: The place where moving forward means moving backwards. Member No.: 8,528 ![]() |
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">
|
|
|
|
Mar 30 2008, 04:18 PM
Post
#9
|