i am trying to create a simple guestbook to include in a web site. i cant get the form to add the data to the database nevermind post the entries. there are 3 files guestbook, addguestbook and view guestbook. im using server2go and dont know whether there is something in the config file that i have not changed properly. all the pages are stored in htdocs. heres the coding for the pages.

guestbook

<table width="400" border="0" align="center" cellpadding="3" cellspacing="0">
<tr>
<td><strong>Test Sign Guestbook </strong></td>
</tr>
</table>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form id="form1" name="form1" method="post" action="addguestbook.php">
<td>
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td width="117">Name</td>
<td width="14">:</td>
<td width="357"><input name="name" type="text" id="name" size="40" /></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input name="email" type="text" id="email" size="40" /></td>
</tr>
<tr>
<td valign="top">Comment</td>
<td valign="top">:</td>
<td><textarea name="comment" cols="40" rows="3" id="comment"></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Submit" /> <input type="reset" name="Submit2" value="Reset" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
<table width="400" border="0" align="center" cellpadding="3" cellspacing="0">
<tr>
<td><strong><a href="viewguestbook.php">View Guestbook</a> </strong></td>
</tr>
</table>

addguestbook

<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="mywebsite"; // Database name
$tbl_name="guestbook"; // Table name

mysql_connect("$host", "$username", "$password")or die("cannot connect server ");
mysql_select_db("$db_name")or die("cannot select DB");

$datetime=date("y-m-d h:i:s"); //date time

$sql="INSERT INTO $tbl_name(name, email, comment, datetime)VALUES('$name', '$email', '$comment', '$datetime')";
$result=mysql_query($sql);

//check if query successful
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='viewguestbook.php'>View guestbook</a>"; 

else {
echo "ERROR";
}

mysql_close();
?>

view guestbook

<table width="400" border="0" align="center" cellpadding="3" cellspacing="0">
<tr>
<td><strong>View Guestbook | <a href="guestbook.php">Sign Guestbook</a> </strong></td>
</tr>
</table>
<br>

<?php

$host="localhost"; 
$username="root"; 
$password="";
$db_name="mywebsite";
$tbl_name="guestbook";

mysql_connect("$host", "$username", "$password")or die("cannot connect server ");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);

while($rows=mysql_fetch_array($result)){
?>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td><table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td>ID</td>
<td>:</td>
<td><? echo $rows['id']; ?></td>
</tr>
<tr>
<td width="117">Name</td>
<td width="14">:</td>
<td width="357"><? echo $rows['name']; ?></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><? echo $rows['email']; ?></td>
</tr>
<tr>
<td valign="top">Comment</td>
<td valign="top">:</td>
<td><? echo $rows['comment']; ?></td>
</tr>
<tr>
<td valign="top">Date/Time </td>
<td valign="top">:</td>
<td><? echo $rows['datetime']; ?></td>
</tr>
</table></td>
</tr>
</table>
<BR>
<?
}
mysql_close(); //close database
?>

and also here is the database part of the config file

[database]
;--- 1 if MySQL Server should be started
UseMySQL=1
;--- 1 if the database files from the dbdir directory will be mirrored to
;--- a directory of the local machine
LocalMirror=0
;--- 1 if the mirrored database should be overwritten at each start of the
;--- the server
OverwriteLocalMirror=0
;--- The path to that the database should be mirrored (e.g.. c:\MyS2GApp\Data\) , if empty the
;--- default temp directory is used
MirrorFolder=C:\Users\Steffi\Desktop\dissertation second site\server\distribute_apache2.0\dbdir
;--- If value is 1 all files of the database server will be deleted after
;--- Server shutdown
DeleteDatabaseFiles=0
;--- The port that should be used for MySQL. If empty the default mysql port is used
MySQLPort=7188
;--- Commandline parameters (i.e. skip-innodb)
MySQLCmd=--skip-innodb
;--- If HideMirrorFolder is set to 1 the folder will created as hidden folder
HideMirrorFolder=0

if anyone could help me out i would be very grateful, as the web site is for my dissertation at uni. iv tried looking at other tutorials and even trying them out but the result is always the same. :(

Recommended Answers

All 3 Replies

Ok the issue from what I can see is the way in wich you are connecting to the database.

Try this method:

$con = mysql_connect( "SERVER" , "USERNAME" , "PASSWORD" )
or die( "Could not connect: " . mysql_error() );
$db = mysql_select_db( "DATABASE" , $con );

This should work and also give you any errors whilst connecting to the database. Please note before making the site live please remove the or die statement.

I had similar problems with server2go and it seems very difficult / impossible to add things to a database on it. I too played withits config file for hours of endless confusion.

I switched to using usbwebserver (http://www.usbwebserver.net/en/) which completely wipes the floor with server2go. I now use it as my home test server, and to distribute to a couple of clients the current state of things I'm building for them. And once they have got it running, I can send them just the files that have been updated to copy and paste.

Usbwebserver has removed a mailing program it originally used, as it gave false malware warnings because malware that took over people's PCs used the same mailing program and got it a bad reputation (the mailer, not Usbwebserver)

Dump server2go, it is for a fixed content database, not an editable one.

EDIT Damn, I didn't notice the dates and have been tricked by a forum spammer into replying. But my advice is still valid.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.