473,738 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Guestbook - No Error messages nor outcome

34 New Member
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 10341
r035198x
13,262 MVP
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
infoseekar
34 New Member
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
infoseekar
34 New Member
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 Recognized Expert Expert
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
15971
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 is as follows. I have a guestbook type code I'm trying to write, but when the results get printed to a webpage, it outputs completely nothing as what was entered in the guestbook database. No errors appear to be generated, and I can't see if...
4
1378
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 'OK' is 0. You receive a link/message by mail, telling you that there is a new entry. you log in into the admin part, read the message, and set ok to 1 (for instance by checkbox)or delete the message if it's nonsense.
14
26496
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
12915
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 existing book. It will be quite easy using JavaScript to collate the data from a form into a 'database', and write the file with new stuff on my local disk, but can Javascript write to disk on a webhosting server without giving away the ftp...
1
6225
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: - guestbook.jsp -> this is the form - writeToFile -> writing the captured data from the form to a file - readFromFile -> reading all the greetings to the file guestbook.jsp Here is the file Guestbook.jsp: ------------------------------ <!--...
6
11184
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 will include the code I originally used. I understand I should switch from CDONTS to CDO mail but after several sttempts I am finding a very hard time getting the new CDO mail to work properly. Any assistance with this would be greatly...
1
11979
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. There seems to be a lot of server-side processing going on. The guesbooks are setup in such a fashion that when user submits an entry, not only is it posted in the page for public viewing, but I also receive an e-mail letting me kow that the...
0
7060
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
25641
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 with it a little and it's closer but not quite right. I made a database named 'guestbook' with a table named 'visitors'. In it are the following fields: TimeStamp Name Last email comment Here is the code to the guestbook (guestbook.php),...
0
8968
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8787
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9259
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9208
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8208
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6750
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4569
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.