Please login or register. Welcome to the Studio, guest!


Quick Links:


newBookmarkLockedFalling

Gunny

Gunny Avatar
Go Team Tux!

**
Official Member

37


November 2005
I'm trying to make a guest book script:

I get this error on the last page:

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

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in c:\program files\easyphp1-8\www\php\viewguestbook.php on line 24

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in c:\program files\easyphp1-8\www\php\viewguestbook.php on line 29

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in c:\program files\easyphp1-8\www\php\viewguestbook.php on line 31


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.


Llanilek

Llanilek Avatar
Former Elite Mod

****
Dedicated Studio Member

931


October 2005
$dbHost = "localhost";
$dbUser = "";
$dbPass = "";
$dbname = "guestbook";

you need to fill them in correctly...

are u using a mysql database for this?

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
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. :P

Llanilek

Llanilek Avatar
Former Elite Mod

****
Dedicated Studio Member

931


October 2005
erm exactly what i just said chris?

:P

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

Gunny

Gunny Avatar
Go Team Tux!

**
Official Member

37


November 2005
I'm using EasyPHP with a username of 'root' and no password.

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
$dbUser = "";

Username isn't filled in then. :P

Llanilek

Llanilek Avatar
Former Elite Mod

****
Dedicated Studio Member

931


October 2005
bakura said:
$dbHost = "localhost";
$dbUser = "";
$dbPass = "";
$dbname = "guestbook";

you need to fill them in correctly...

are u using a mysql database for this?



:P



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

Gunny

Gunny Avatar
Go Team Tux!

**
Official Member

37


November 2005
Does work. Thanks for the help.

newBookmarkLockedFalling