473,414 Members | 1,988 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Guestbook - No Error messages nor outcome

HI Guys

I am a beginner.
I am trying to create a guestbook. I have the code for it and it is in three parts. Part 1 "dp.php" to open database and make connection Part 2 "index.php" which will show the guestbook entries and Part 3 "add.php" to add new entry.

The problems is when i run any of the file nothing happens i.e. no error(s) and no result.

I tired to check the code so many times and couldnt any find any errors.

Part 1

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $user="user";
  4. $host="localhost";
  5. $password="password";
  6. $database = "test";
  7.  
  8.  $connection = mysql_connect($host,$user,$password) //open connection to MySQL
  9.        or die ("couldn't connect to server");
  10.  
  11.  
  12.   $db = mysql_select_db($database,$connection) // open session to Database
  13.        or die ("Couldn't select database");
  14.  
  15. mysql_select_db("$db", $connection);
  16. ?>
  17.  
Part 2

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3.  
  4. ****$sql*=*"SELECT text*FROM*guestbook*ORDER*BY*insertdate*DESC";
  5. ****$result*=*mysql_query($sql);
  6. ?>
  7.  
  8. <html>
  9. <body>
  10. ****<a href="add.php">Add*a*comment</a>
  11. ****<h1>Guestbook</h1>
  12. ****<br/><table>****
  13. <?php*while*($row*=*mysql_fetch_assoc($result))*{*?>
  14. *********<tr><th><?php*echo*$row['name']."*-*".$row['insertdate'];*?></th></tr>
  15. *********<tr><td><?php*echo*nl2br($row['text']);*?></td></tr>
  16. <?php*}*?>
  17. ****</table>****
  18. </body> 
  19. </html>
  20.  
Part 3

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3.  
  4. include 'dp.php';
  5.  
  6. if (isset($_POST['submitBtn'])) 
  7. {
  8.          $name     = (isset($_POST['name'])) ? addslashes(htmlentities($_POST['name'])) : '' ;
  9.          $comment  = (isset($_POST['comment'])) ? addslashes(htmlentities($_POST['comment'])) : '' ;
  10.          $actDate  = date("d-m-Y H:i:s");
  11.  
  12.          //Minimum name and comment length.
  13.          if ((strlen($name) > 2) && (strlen($comment) > 5))
  14.     {
  15.              $sql = "INSERT INTO guestbook (name,text,insertdate) VALUES ('$name','$comment','$actDate')";
  16.              mysql_query($sql);
  17.          }
  18.  
  19.          header("Location: index.php");
  20. }
  21.     else {
  22.  
  23. ?>
  24.  
  25. <html>
  26. <body>
  27.   <h1>Add comment</h1>
  28.   <form action= method="post" name="gbook">
  29.     <table>
  30.       <tr><th>Name:</th><td><input type="text" name="name" id="name"/></td></tr>
  31.       <tr><th>Comment:</th>
  32.           <td><textarea name="comment" cols=30 rows=5></textarea></td>
  33.       </tr>
  34.       <tr><td colspan="2" align="center">
  35.           <input type="submit" name="submitBtn" id="submitBtn" value="Add comment"/></td>
  36.       </tr>
  37.     </table>  
  38.  </form>
  39. </body>    
  40.  
  41. <?php } ?>    
  42.  
  43. </html> 
  44.  
Thanks in Advance

Regards
Zeshan
Jul 25 '08 #1
4 10286
r035198x
13,262 8TB
First let's make sure your code for connecting to the database works. Put some echo statements to tell us what is happening. Specifically put an echo at the end saying something like "Database connection successful".
Jul 25 '08 #2
First let's make sure your code for connecting to the database works. Put some echo statements to tell us what is happening. Specifically put an echo at the end saying something like "Database connection successful".
Thanks for replying.

Code for connecting to the database works. It echo Database connection successful. Now bit of "index.php" works. I can see a link for Add comment page and heading "Guestbook". On the same page (index.php) I should be able to see a form as well but i dont see nothing and "add.php" doesnt work at all i.e. no error messages.

Thanks

EDIT: ERROR: UNEXPECTED T_VARIABLE IN LINE 3 (INDEX.PHP)
Jul 25 '08 #3
UNEXPECTED T_VARIABLE ERROR IN LINE 3 (INDEX.PHP) IS SOLVED.

BUT I still dont see the form.

thanks
Jul 25 '08 #4
Atli
5,058 Expert 4TB
Hi.

The second mysql_select_db call in Part1 is most likely causing problems.
You are assigning the boolean return value from the first one to a variable, and then passing that to the second one.

Try removing the second call all together and see what happens.

And btw... what's up with all the * chars in Part2?
Jul 26 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Dariusz | last post by:
I am a beginner in PHP and MySQL, and am working through a book and various online tutorials on PHP and MySQL and now stuck - installed everything on "localhost" and it all works fine. My question...
4
by: knoak | last post by:
If a filter with bad words etc. isn't what you mean, you could put an extra field in the DB, called 'OK' or something like that. When someone enters a message in the GB, the initial value of...
14
by: pcchong | last post by:
I use a free database-driven ASP guestbook. I want to add a IP address blocking filter to it( just to block one particular guest). What is the easiest way to do so? Thanks. pcchong
2
by: Chris Wilkinson | last post by:
Hi there, I wish to create a guestbook for a small business website I made. The guestbook will be your standard 'form page' with button click to 'send' type thing, plus another link to view the...
1
by: Rune Runnestř | last post by:
Hi, I have made a small program that doesn't work quite the way it should. It is a guestbook for the web, where visitors can write back their greetings. The program consists of 3 files: -...
6
by: DigitalRick | last post by:
I have been running CDONTS in my ASPpages to send emails to me sent from my guestbook. It had been working fine untill I upgraded to Server 2003 (I am also running Exchange 2003) all locally. I...
1
by: Viken Karaguesian | last post by:
Hello everyone, Just wanting some advice. I'd like to start removing the Microsoft-generated guestbook (a feature of FrontPage) on my websites but I'm not sure if it can be done just using HTML....
0
by: http://www.free-guestbook.net/gbook.php?u=21740 | last post by:
http://www.free-guestbook.net/gbook.php?u=21740 http://www.free-guestbook.net/gbook.php?u=21741 http://www.free-guestbook.net/gbook.php?u=21742 http://www.free-guestbook.net/gbook.php?u=21743
5
Thekid
by: Thekid | last post by:
Hi, I'm using xampplite and I'm trying to make a guestbook and a forms page where you can post to the guestbook with PHP & MySQL. I got the code from a website but it wasn't working so I tinkered...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.