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
[code=php]
<?php
$user="user";
$host="localhos t";
$password="pass word";
$database = "test";
$connection = mysql_connect($ host,$user,$pas sword) //open connection to MySQL
or die ("couldn't connect to server");
$db = mysql_select_db ($database,$con nection) // open session to Database
or die ("Couldn't select database");
mysql_select_db ("$db", $connection);
?>
[/code]
Part 2
[code=php]
<?php
****$sql*=*"SEL ECT text*FROM*guest book*ORDER*BY*i nsertdate*DESC" ;
****$result*=*m ysql_query($sql );
?>
<html>
<body>
****<a href="add.php"> Add*a*comment</a>
****<h1>Guestbo ok</h1>
****<br/><table>****
<?php*while*($r ow*=*mysql_fetc h_assoc($result ))*{*?>
*********<tr><t h><?php*echo*$r ow['name']."*-*".$row['insertdate'];*?></th></tr>
*********<tr><t d><?php*echo*nl 2br($row['text']);*?></td></tr>
<?php*}*?>
****</table>****
</body>
</html>
[/code]
Part 3
[code=php]
<?php
include 'dp.php';
if (isset($_POST['submitBtn']))
{
$name = (isset($_POST['name'])) ? addslashes(html entities($_POST['name'])) : '' ;
$comment = (isset($_POST['comment'])) ? addslashes(html entities($_POST['comment'])) : '' ;
$actDate = date("d-m-Y H:i:s");
//Minimum name and comment length.
if ((strlen($name) > 2) && (strlen($commen t) > 5))
{
$sql = "INSERT INTO guestbook (name,text,inse rtdate) VALUES ('$name','$comm ent','$actDate' )";
mysql_query($sq l);
}
header("Locatio n: 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>
[/code]
Thanks in Advance
Regards
Zeshan
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
[code=php]
<?php
$user="user";
$host="localhos t";
$password="pass word";
$database = "test";
$connection = mysql_connect($ host,$user,$pas sword) //open connection to MySQL
or die ("couldn't connect to server");
$db = mysql_select_db ($database,$con nection) // open session to Database
or die ("Couldn't select database");
mysql_select_db ("$db", $connection);
?>
[/code]
Part 2
[code=php]
<?php
****$sql*=*"SEL ECT text*FROM*guest book*ORDER*BY*i nsertdate*DESC" ;
****$result*=*m ysql_query($sql );
?>
<html>
<body>
****<a href="add.php"> Add*a*comment</a>
****<h1>Guestbo ok</h1>
****<br/><table>****
<?php*while*($r ow*=*mysql_fetc h_assoc($result ))*{*?>
*********<tr><t h><?php*echo*$r ow['name']."*-*".$row['insertdate'];*?></th></tr>
*********<tr><t d><?php*echo*nl 2br($row['text']);*?></td></tr>
<?php*}*?>
****</table>****
</body>
</html>
[/code]
Part 3
[code=php]
<?php
include 'dp.php';
if (isset($_POST['submitBtn']))
{
$name = (isset($_POST['name'])) ? addslashes(html entities($_POST['name'])) : '' ;
$comment = (isset($_POST['comment'])) ? addslashes(html entities($_POST['comment'])) : '' ;
$actDate = date("d-m-Y H:i:s");
//Minimum name and comment length.
if ((strlen($name) > 2) && (strlen($commen t) > 5))
{
$sql = "INSERT INTO guestbook (name,text,inse rtdate) VALUES ('$name','$comm ent','$actDate' )";
mysql_query($sq l);
}
header("Locatio n: 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>
[/code]
Thanks in Advance
Regards
Zeshan
Comment