Click to See Complete Forum and Search --> : Can anyone help with this error i keep getting?


hoogeebear
11-23-2007, 09:06 AM
Hi!

here are the two errors I get. Im trying to get the entries(name, email, comment) the user enter into my guestbook and store them in my database.

Here is my PHP code for doing this:

<?php
require ($_SERVER["DOCUMENT_ROOT"]. "/config/config_db.php");
$connection = @mysql_connect($db_host, $db_user, $db_password) or die('Could not connect: ' . mysql_error());
mysql_select_db($db_name, $connection);

$name = $_POST["txt_name"];
$len - strlen($name);
//Only write to database if there is a name
if ($len > 0)
{
$email = $_POST["txt_email"];
$comment = $_POST["txt_comment"];

$query = "INSERT INTO guestbook (name, email, comment) VALUES ('$name', '$email', '$comment')";
mysql_query($query, $connection) or die(mysql_error());
}

?>

<html>
<head>
<title>Welcome to my GuestBook</title>
</head>
<body>
<center>
<form action="<?php echo $_Server[PHP_SELF]; ?>" method="POST">
<font face = "arial" size ="1">
Name: <input type="text" name = "txt_name">&nbsp;
Email: <input type="text" name = "txt_email"><br><br>
Comments:<br>
<textarea style = "width: 75%" rows = "10" name = "txt_comment"></textarea>
<center><input type ="submit" value="Submit"></center>
</font>
</form>

</center>
</body>
</html>


Here are the errors I get:

Warning: require(C:/Program Files/XAMP/xampp/htdocs/config/config_db.php) [function.require]: failed to open stream: No such file or directory in C:\Program Files\XAMP\xampp\htdocs\john\guestbook.php on line 2

Fatal error: require() [function.require]: Failed opening required 'C:/Program Files/XAMP/xampp/htdocs/config/config_db.php' (include_path='.;C:\Program Files\XAMP\xampp\php\pear\') in C:\Program Files\XAMP\xampp\htdocs\john\guestbook.php on line 2

Any help wouild be really appreciated.

tca
11-23-2007, 10:39 AM
require ($_SERVER["DOCUMENT_ROOT"]. "/config/config_db.php");

Try: require ("config/config_db.php");

$len - strlen($name);

Try: $len = strlen($name);

TC

hoogeebear
11-23-2007, 10:55 AM
Hey!
Tanx for the response, I figured it out about 10 mins ago!

Another problem has arisen though. A completely new 1!

I searched google but cant seem to find a solution. Im trying to get the what the user enters(name, email.comment) to appear in a table below the top table. Hope that makes sense! Here is my code and my error.

Code:

<?php
$db_host = "localhost";
$db_user = "";
$db_password = "";
$db_name = "survey";

$name = $_POST["txt_name"];
$len - strlen($name);
//Only writes to database if there is a name, email and comment entered.
if ($len > 0)
{
$email = $_POST["txt_email"];
$comment = $_POST["txt_comment"];

$query = "INSERT INTO guestbook (name, email, comment) VALUES ('$name', '$email', '$comment')";
mysql_query($query, $connection) or die(mysql_error());
}

?>

<html>
<head>
<title>Welcome to my GuestBook</title>
</head>
<body>
<center>
<form action="<?php echo $_Server[PHP_SELF]; ?>" method="POST">
<font face = "arial" size ="1">
Name: <input type="text" name = "txt_name">&nbsp;
Email: <input type="text" name = "txt_email"><br><br>
Comments:<br>
<textarea style = "width: 75%" rows = "10" name = "txt_comment"></textarea>
<center><input type ="submit" value="Submit"></center>
</font>
</form>

<table bgcolor="#AAAAAA" border = "0" width = "75%" cellspacing = "1" celloadding = "2">
<?php
$query = "SELECT * FROM guestbook ORDER BY name";
$result = mysql_query($query, $connection);

for ($i =0; $i < mysql_num_rows($result); $i++)
{
$name = mysql_result($result, $i, "name");
$email = mysql_result($result, $i, "email");
$email_len = strlen ($email);
$comment = mysql_result($result, $i, "comment");

echo '
<tr>
<td width = "50%" bgcolor = "#EEEEEE">
<font face = "arial" size = "2">';
if ($email_len > 0)
{
echo '<b>Name:</b> <a href="mailto:'.$email.'>"'.$name.'</a>';
}
else
{
echo '<b>Name:</b> '.$name;
}
echo '
<br>
<b>Comment:</b> '.$comment.'
</font>
</td>
</tr>
';


}
?>
</table>

</center>
</body>
</html>

Here is the error:

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\Program Files\XAMP\xampp\htdocs\john\guestbook.php on line 40

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Program Files\XAMP\xampp\htdocs\john\guestbook.php on line 42


Tanx for helpin me with this dude....

tca
11-23-2007, 06:50 PM
This query $query = "SELECT * FROM guestbook ORDER BY name"; is not connected to the DB correctly.

I'm not seeing where you actually made $connection.

TC

hoogeebear
12-01-2007, 04:49 AM
I feel like such a dummie for not seeing that! Tanx anyway! Im such a newbie!