Jump to content

[SOLVED] Help with Guestbook


darkfreaks

Recommended Posts

my page appears blank can anyone point out any errors i may have overlooked?

 

 

<?php

include('connect.php');

$datetime=date("D M j G:i:s T Y"); //date time
$name=$_POST[name];
$comment=$_POST[comment];
$email=$_POST[email];





if($_POST[comment]=="") {$error[comment]="Please enter a comment";} else {unset($error[comment]);} 

if($_POST[name]=="") {$error[name]="Please enter a name";} else {unset($error[name]);} 

if($_POST[email]=="") {$error[email]="Please enter an email";} else {unset($error[email]);} 
?>
<?php if ($error) { ?>

<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" >
<tr>
<form id="form1" name="form1" method="post" ">
<td>
<table width="400" border="0" cellpadding="3" cellspacing="1">
<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> </td>
<td> </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>

<?php
}else{
$sql="INSERT INTO guestbook(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>"; // link to view guestbook page 
}


mysql_close();
}
?>

Link to comment
Share on other sites

I have copied your code and pasted to a file named test.php. When I browse to that page I did show the form with bunch of errors. So I don't see why would you not see anything on the page. I think the possible problem is on connect.php. Some error on that page might have causing your page to show nothing..

Link to comment
Share on other sites

my version

 

<?php

include("connect.php");

$datetime=date("D M j G:i:s T Y"); //date time

$name=addslashes($_POST['name']);

$comment=addslashes($_POST['comment']);

$email=addslshes($_POST['email']);

if( ($_POST['comment']=="") || ($_POST['name']=="") || ($_POST['email']=="") ){

echo "Please Fill In All The Form";

}else{

$sql="INSERT INTO guestbook(name, email, comment, datetime)VALUES('$name', '$email', '$comment', '$datetime')";
$result=mysql_query($sql)or die("mysql_error()");

if(mysql_affected_rows($result)){


echo "<center>

Thank you Guessbook updated

<br><br>

</center>";

}

}
?>

<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" >
<tr>
<form id="form1" name="form1" method="post" ">
<td>
<table width="400" border="0" cellpadding="3" cellspacing="1">
<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> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Submit" /> <input type="reset" name="Submit2" value="Reset" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.