Hello,
Thank you in advance for any help I may receive. I am a newbie to PHP/MySQL/Apache.
I followed the instructions to install the aforementioned applications from a book titled Sams Teach Yourself PHP, MYSQL, and Apache All in One. When I attempt to enter test data into my form after entering http://localhost/addtopic.html onto my web browser, I receive a 'HTTP 500 Internal server error' message...The page cannot be displayed. When I check my Apache HTTP Server 2.2 error log, the following error displays:
PHP Fatal error:Call to undefined function doDB() in C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\do_addtopic.php on line 3, referer: http://localhost/addtopic.html
I need help on deciphering why I am obtaining this PHP Fatal error message and how to fix it.
Thanks!!!
PHP Fatal Error Message
Moderator: General Moderators
Re: PHP Fatal Error Message
hmmm... one thing i hate doing is setup of php, apache, and mysql separetely... that's why i use WAMP or XAMPP or EasyPHP
Re: PHP Fatal Error Message
Thanks for your reply McInfo .
The content of my addtopic.html is the following (Location: C://Program Files/Apache Software Foundation/Apache 2.2/htdocs):
The content of my addtopic.html is the following (Location: C://Program Files/Apache Software Foundation/Apache 2.2/htdocs):
Code: Select all
<html>
<head>
<title>Add a Topic</title>
</head>
<body>
<h1>Add a Topic</h1>
<form method="post" action="do_addtopic.php">
<p><strong>Your E-Mail Address:</strong><br/>
<input type="text" name="topic_owner" size="40" maxlength="150"/></p>
<p><strong>Topic Title:</strong><br/>
<input type="text" name="topic_title" size="40" maxlength="150"/></p>
<p><strong>Post Text:</strong><br/>
<textarea name="post_text" rows="8" cols="40" wrap="virtual"></textarea></p>
<p><input type="submit" name="submit" value="Add Topic"></p>
</form>
</body>
</html>
Last edited by Benjamin on Tue May 05, 2009 1:01 am, edited 1 time in total.
Reason: Added code=html tags.
Reason: Added code=html tags.
Re: PHP Fatal Error Message
Thanks McInfo. Please view my do_addtopic.php below.
Also, I see this script displays include("ch21_include.php"); at the beginning. The script for ch21_include.php may be found below.
Code: Select all
<?php
include("ch21_include.php");
doDB();
//check for required fields from the form
if ((!$_POST["topic_owner"]) || (!$_POST["topic_title"]) || (!$_POST["post_text"])) {
header("Location: addtopic.html");
exit;
}
//create and issue the first query
$add_topic_sql = "INSERT INTO forum_topics (topic_title, topic_create_time,topic_owner) VALUES ('".$_POST["topic_title"]."',now(), '".$_POST["topic_owner"]."')";
$add_topic_res = mysqli_query($mysqli, $add_topic_sql) or die(mysqli_error($mysqli));
//get the id of the last query
$topic_id = mysqli_insert_id($mysqli);
//create and issue the second query
$add_post_sql = "INSERT INTO forum_posts (topic_id,post_text,post_create_time,post_owner) VALUES ('".$topic_id."', '".$_POST["post_text"]."', now(), '".$_POST["topic_owner"]."')";
$add_post_res = mysqli_query($mysqli, $add_post_sql) or die(mysqli_error($mysqli));
//close connection to MySQL
mysqli_close($mysqli);
//create nice message for user
$display_block = "<P>The <strong>".$_POST["topic_title"]."</strong> topic has been created.</p>";
?>
<html>
<head>
<title>New Topic Added</title>
</head>
<body>
<h1>New Topic Added</h1>
<?php echo $display_block; ?>
</body>
</html>
Also, I see this script displays include("ch21_include.php"); at the beginning. The script for ch21_include.php may be found below.
Code: Select all
<?
//set up a couple of functions for use by scripts in ch21
function doDB() {
global $mysqli;
//connect to server and select database; you may need it
$mysqli = mysqli_connect("localhost", "joeuser", "somepass", "testDB");
//if connection fails, stop script execution
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
}
?>