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. :(

Dani AI

Generated

Most likely causes (quick summary): a PHP parse/runtime error in the insert script, the script never reading the POSTed fields, or a connection to the wrong MySQL port. was right to suggest surfacing connection errors, and ’s comment about server2go’s quirks is relevant — some portable servers use nonstandard ports or are configured for read-only snapshots.

Practical troubleshooting checklist:

  • Turn on full PHP errors so parse/runtime problems become visible (error_reporting and display_errors).
  • Confirm files are served by HTTP (...) not opened with file://; PHP will not run otherwise.
  • Run addguestbook.php directly in the browser to catch parse errors (missing braces or syntax will stop execution).
  • Verify the script reads the POST inputs ($_POST['name'], etc.) before building the SQL.
  • If server2go uses a custom MySQL port, include it in the host string (for example “127.0.0.1:PORT”) when connecting.
  • Show MySQL errors from mysql_query/mysql_connect (use mysql_error()) so failed queries give a diagnostic.
  • Check table schema (columns and types) and that the datetime column accepts the inserted format.

Example minimal fix (focuses on the missing pieces: POST retrieval, escaping, error output and port-aware connection):

<?php
error_reporting(E_ALL);
ini_set('display_errors',1);

$host = '127.0.0.1:7188'; // include custom port if needed
$user = 'root'; $pass = ''; $db = 'mywebsite'; $tbl = 'guestbook';

$link = mysql_connect($host,$user,$pass) or die('Connect error: '.mysql_error());
mysql_select_db($db,$link) or die('DB select error: '.mysql_error());

$name    = isset($_POST['name']) ? mysql_real_escape_string(trim($_POST['name'])) : '';
$email   = isset($_POST['email']) ? mysql_real_escape_string(trim($_POST['email'])) : '';
$comment = isset($_POST['comment']) ? mysql_real_escape_string(trim($_POST['comment'])) : '';
$dt = date('Y-m-d H:i:s');

$sql = "INSERT INTO `$tbl` (`name`,`email`,`comment`,`datetime`) VALUES ('$name','$email','$comment','$dt')";
if (!mysql_query($sql,$link)) { echo 'Insert error: '.mysql_error(); }
mysql_close($link);
?>

Notes: escape output in viewguestbook (use htmlspecialchars) to avoid XSS. For any modern PHP environment, migrate away from deprecated mysql_* functions to mysqli or PDO. If server2go continues to be problematic, a different portable stack or a local XAMPP/WAMP install is a faster route for editing databases.

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.

Thank you for the opportunity. Like what you do here..

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.