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 -
<?php
-
-
$user="user";
-
$host="localhost";
-
$password="password";
-
$database = "test";
-
-
$connection = mysql_connect($host,$user,$password) //open connection to MySQL
-
or die ("couldn't connect to server");
-
-
-
$db = mysql_select_db($database,$connection) // open session to Database
-
or die ("Couldn't select database");
-
-
mysql_select_db("$db", $connection);
-
?>
-
Part 2 -
-
<?php
-
-
****$sql*=*"SELECT text*FROM*guestbook*ORDER*BY*insertdate*DESC";
-
****$result*=*mysql_query($sql);
-
?>
-
-
<html>
-
<body>
-
****<a href="add.php">Add*a*comment</a>
-
****<h1>Guestbook</h1>
-
****<br/><table>****
-
<?php*while*($row*=*mysql_fetch_assoc($result))*{*?>
-
*********<tr><th><?php*echo*$row['name']."*-*".$row['insertdate'];*?></th></tr>
-
*********<tr><td><?php*echo*nl2br($row['text']);*?></td></tr>
-
<?php*}*?>
-
****</table>****
-
</body>
-
</html>
-
Part 3 -
-
<?php
-
-
include 'dp.php';
-
-
if (isset($_POST['submitBtn']))
-
{
-
$name = (isset($_POST['name'])) ? addslashes(htmlentities($_POST['name'])) : '' ;
-
$comment = (isset($_POST['comment'])) ? addslashes(htmlentities($_POST['comment'])) : '' ;
-
$actDate = date("d-m-Y H:i:s");
-
-
//Minimum name and comment length.
-
if ((strlen($name) > 2) && (strlen($comment) > 5))
-
{
-
$sql = "INSERT INTO guestbook (name,text,insertdate) VALUES ('$name','$comment','$actDate')";
-
mysql_query($sql);
-
}
-
-
header("Location: index.php");
-
}
-
else {
-
-
?>
-
-
<html>
-
<body>
-
<h1>Add comment</h1>
-
<form action= method="post" name="gbook">
-
<table>
-
<tr><th>Name:</th><td><input type="text" name="name" id="name"/></td></tr>
-
<tr><th>Comment:</th>
-
<td><textarea name="comment" cols=30 rows=5></textarea></td>
-
</tr>
-
<tr><td colspan="2" align="center">
-
<input type="submit" name="submitBtn" id="submitBtn" value="Add comment"/></td>
-
</tr>
-
</table>
-
</form>
-
</body>
-
-
<?php } ?>
-
-
</html>
-
Thanks in Advance
Regards
Zeshan
4 10341
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".
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)
UNEXPECTED T_VARIABLE ERROR IN LINE 3 (INDEX.PHP) IS SOLVED.
BUT I still dont see the form.
thanks
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?
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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.
|
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
|
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...
|
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:
------------------------------
<!--...
| |
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...
|
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...
|
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
|
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),...
|
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...
|
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,...
| |
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,...
|
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...
|
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...
|
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...
|
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();...
|
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...
| |
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
| |