|
I'm trying to make a guest book script:
I get this error on the last page:
This is the code: signguestbook.php
<html> <body> <form name="signguestbook" method="POST" action="addmessage.php"> <table cellspacing="4" style="padding: 0px; width: 500px; border: 0px;"> <tr> <td align="right"><b>Name:</b></td><td><input type="text" name="name" /></td> </tr>
<tr> <td align="right"><b>EMail:</b></td><td><input type="text" name="email" /></td> </tr>
<tr> <td colspan="2" align="center"><b>Comment:</b><br /> <textarea name="comment" rows="5" cols="50"></textarea></td> </tr>
<tr> <td colspan="2" align="center"><input type="reset" name="reset" value="RESET" /> <input type="submit" name="submit" value="SUBMIT" /></td> </tr> </table> </form> <a href='/php/viewguestbook.php'>View the guestbook</a> </body> </html>
addmessage.php
<?php function safeAddSlashes($string) { if (get_magic_quotes_gpc()) { return $string; } else { return addslashes($string); } }
function mailcheck($emailadr){ if (eregi("^[a-zA-Z0-9_.-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$", $emailadr)) return $emailadr; else return false; }
$name = $_POST['name']; $email = $_POST['email']; $comment = $_POST['comment']; $datetime = date("Y-m-d");
$comment = safeAddSlashes($comment); $email = mailcheck($email);
$dbHost = "localhost"; $dbUser = "root"; $dbPass = ""; $dbname = "guestbook";
$db = mysql_connect($dbHost,$dbUser,$dbPass); mysql_select_db($dbname,$db);
$sql="INSERT INTO guestbook (`name`, `email`, `dateposted`, `comment`) VALUES ('$name', '$email', '$datetime', '$comment')";
$result = mysql_query($sql, $db);
if ($result) { echo 'Thank you, your message has been entered successfully<br />'; echo 'To view the guestbook click <a href="viewguestbook.php" title="View Guestbook">here</a>.'; } else echo 'Your message could not be added.'; ?>
viewguestbook.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title></title>
</head>
<body>
<h3>View Guestbook</h3>
<?php $dbHost = "localhost"; $dbUser = ""; $dbPass = ""; $dbname = "guestbook";
$db = mysql_connect($dbHost,$dbUser,$dbPass); mysql_select_db($dbname,$db);
$requete = "SELECT ID, name, email, dateposted, comment FROM guestbook ORDER BY ID desc"; $result = mysql_query ($requete,$db);
while($row = mysql_fetch_assoc($result)) { $name = $row['name']; $email = $row['email']; $comment = $row['comment']; $datetime = $row["dateposted"];
if ($email) echo '<a href="mailto:'.$email.'">'; echo $name; if ($email) echo '</a>'; echo ' - Posted on '.$datetime.'<br />'; echo ''.$comment.''; echo '<hr />'; } ?>
</body> </html>
Any help would be really great.
|
|
|
|
$dbHost = "localhost"; $dbUser = ""; $dbPass = ""; $dbname = "guestbook";
you need to fill them in correctly...
are u using a mysql database for this?
|
|
|
|
|
Warning: mysql_connect(): Access denied for user 'ODBC'@'localhost' (using password: NO) in c:\program files\easyphp1-8\www\php\viewguestbook.php on line 23 Means some of your data is wrong in the MySQL connection.
|
|
|
|
|
erm exactly what i just said chris? ODBC is what is standard when the incorrect information has been passed through a query... usually the username is wrong when that comes up and also if using password (NO) shows up means that the password is also incorrect
|
|
|
|
|
I'm using EasyPHP with a username of 'root' and no password.
|
|
|
|
$dbUser = ""; Username isn't filled in then.
|
|
|
|
|
$dbHost = "localhost"; $dbUser = ""; $dbPass = ""; $dbname = "guestbook"; you need to fill them in correctly... are u using a mysql database for this?
ok then gunny you need to add root to ur $dbUser variable.. because at the moment its empty
Last Edit: Feb 23, 2006 0:36:58 GMT by Llanilek
|
|
|
|
|
Does work. Thanks for the help.
|
|
|