Jump to content

Recommended Posts

i keep getting error but i can't find anyhting wrong here's the three different pages

 

guestbook.php

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />

<title>Untitled Document</title></head>

 

<body>

 

<table width="400" border="0" align="center" cellpadding="3" cellspacing="0">

<tr>

<td><strong>Rate this Restaurant </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>Subject</td>

<td>:</td>

<td><input name="subject" type="text" id="subject" 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">Check out everyones comments</a> </strong></td>

</tr>

</table>

</body>

</html>

 

 

 

and here is        addguestbook.php

 

<?php

$host="localhost"; // Host name

$username="root"; // Mysql username

$password=""; // Mysql password

$db_name="test"; // Database name

$tbl_name="guestbook"; // Table name

 

// Connect to server and select database.

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, subject, comment, datetime)VALUES('$name', '$email', '$comment','$subject' '$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

}

 

else {

echo "ERROR";

}

 

mysql_close();

?>

 

 

please help i just don't understand

Link to comment
https://forums.phpfreaks.com/topic/48333-solved-simple-guestbook-not-so-simple/
Share on other sites

Whats the error your getting?

 

Just gotta do this :P

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

// Connect to server and select database.
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, subject, comment, datetime)VALUES('$name', '$email', '$comment','$subject' '$datetime')";
$result=mysql_query($sql);

//check if query successful
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='viewguestbook.php'>View guestbook[/url]"; // link to view guestbook page
}

else {
echo "ERROR";
}

mysql_close();
?>

the error i'm getting is the last line

else {

echo "ERROR"

}

 

when i put in my localhost i need http://ect.....  or can i just say localhost and my password i don't have one set can these be any problems?

i'm using WAMP to test this on my cpu

 

thanks

I think its because on the line where you have the link, you have put [/url] instead on </ a>. EDIT no, this is just me being stupid, this automaticall changes [/url] to </ a>?

 

Yeah sure you can just put localhost and your username and password, i dont think theres any probelms with it. You can have the variables you just dont need the "" around them.

sorry that was me bein stupid..

 

Try this...

Change:

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

 

To..

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

replace

$result=mysql_query($sql);

 

with

$result=mysql_query($sql) or die("query error:".mysql_error() );

 

atleast then your see the error

 

personally it looks like and error here

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

 

change to

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

 

that little was comma was the problem!!! thanks now the next issue it doesn't write any of the info in the database. the id is there cause it's an auto inc and the date and time but none of the other info is there?? thanks for so much help everyone

dude you are awsome i would love to give you a donation for your help!!! one more issue now the viewguestbook doesn't work. here's the code.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />

<title>Untitled Document</title>

</head>

 

<body>

<table width="400" border="0" align="center" cellpadding="3" cellspacing="0">

<tr>

<td><strong>Jelly Beans | <a href="guestbook.php">Rate the Bean</a> </strong></td>

</tr>

</table>

<br>

 

<?php

 

$host="localhost"; // Host name

$username = me; // Mysql username

$password = too; // Mysql password

$db_name = test; // Database name

$tbl_name=clearbook; // Table name

 

// Connect to server and select database.

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 valign="top">Subject</td>

<td valign="top">:</td>

<td><? echo $rows['subject']; ?></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

?>

 

 

 

 

</body>

</html>

 

 

now here is the error

 

Parse error: parse error, unexpected $end in C:\wamp\www\clear\viewguestbook.php on line 75

 

 

but seriously i'll throw ya a few bucks if you can help me along the way with this project and i'll donate to phpfreaks thanks a million

humm i can't see any errors

 

Yet some WAMP servers don't support <? and must have <?php

 

so try

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<table width="400" border="0" align="center" cellpadding="3" cellspacing="0">
<tr>
<td><strong>Jelly Beans | <a href="guestbook.php">Rate the Bean </a> </strong></td>
</tr>
</table>



<?php

$host="localhost"; // Host name
$username = me; // Mysql username
$password = too; // Mysql password
$db_name = test; // Database name
$tbl_name=clearbook; // Table name

// Connect to server and select database.
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><?php echo $rows['id']; ?></td>
</tr>
<tr>
<td width="117">Name</td>
<td width="14">:</td>
<td width="357"><?php echo $rows['name']; ?></td>
</tr>
<tr>
<td valign="top">Subject</td>
<td valign="top">:</td>
<td><?php echo $rows['subject']; ?></td>
</tr>
<tr>
<td valign="top">Comment</td>
<td valign="top">:</td>
<td><?php echo $rows['comment']; ?></td>
</tr>
<tr>
<td valign="top">Date/Time </td>
<td valign="top">:</td>
<td><?php echo $rows['datetime']; ?></td>
</tr>
</table></td>
</tr>
</table>
<BR>
<?php
}
mysql_close(); //close database
?>




</body>
</html>

 

 

Note

i assume you have set

 

$username = me; // Mysql username

$password = too; // Mysql password

$db_name = test; // Database name

$tbl_name=clearbook; // Table name

 

correctly

 

ie with quotes

<?php
function filter($string)
{
  $pattern[0] = "/badword1/";
  $pattern[1] = "/badword2/";
  $pattern[2] = "/badword3/";
  $replacement[0] = "####";
  $replacement[1] = "####";
  $replacement[2] = "####";
  return preg_replace($pattern, $replacement, $string);
}
?>

wow thanks everyone let me just clarify what i'm looking at here. for the spam filter i should place the if statement right under the text box for the comments and the bad word filter on the view guestbook page or would this be placed on the page that puts it into the sql database? again i can't express how much these posts have helped me in the learning process of the wonderfu world of php!! Cheers!

awsome, i don't mean to be such a pain in the butt i'm just in the learning process and trying to understand PHP. what's the best way to hide your username password ect. put in a separate config.php file? but if someone found outthe url to it they could still view the source. right?

oh i see!! nice, i was worried about that but i knew there was a way to mask it. also that bad word filter seems to be giving me a problem i don't think i'm putting it in my code right

 

 

<table width="400" border="0" align="center" cellpadding="3" cellspacing="0">

<tr>

<td><strong>11111 | <a href="guestbook.php">Rate</a> </strong></td>

</tr>

</table>

<br>

 

<?php

 

$host=localhost; // Host name

$username = tony; // Mysql username

$password = billy; // Mysql password

$db_name = test; // Database name

$tbl_name=clearbook; // Table name

 

// Connect to server and select database.

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)){

 

?>

 

<?php

function filter($string)

{

  $pattern[0] = "ass";

  $pattern[1] = "/badword2/";

  $pattern[2] = "/badword3/";

  $replacement[0] = "####";

  $replacement[1] = "####";

  $replacement[2] = "####";

  return preg_replace($pattern, $replacement, $string);

}

?>

 

<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><?php echo $rows['id']; ?></td>

</tr>

<tr>

<td width="117">Name</td>

<td width="14">:</td>

<td width="357"><?php echo $rows['name']; ?></td>

</tr>

<tr>

<td valign="top">Subject</td>

<td valign="top">:</td>

<td><?php echo $rows['subject']; ?></td>

</tr>

<tr>

<td valign="top">Comment</td>

<td valign="top">:</td>

<td><?php echo $rows['comment']; ?></td>

</tr>

<tr>

<td valign="top">Date/Time </td>

<td valign="top">:</td>

<td><?php echo $rows['datetime']; ?></td>

</tr>

</table></td>

</tr>

</table>

<BR>

 

 

 

<?php

}

mysql_close(); //close database

?>

 

 

 

 

</body>

</html>

 

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.