I installed PHP 5.0.4 on Windows 2000 Pro, MySQL 4.0.xx running on the same machine. I initially installed PHP using the
installer, but then downloaded the zip file and extracted the ext folder to c:\php\ext.
I have enabled the php_mysql extension in php.ini. I have placed libmysql.dll in c:\windows\system32. Yet when I try to run the jokes.php file from Kevin Yank's book I get these errors:
Fatal error: Call to undefined function mysql_connect() in c:\Inetpub\wwwroot\jokes.php on line 22
PHP Warning: PHP Startup: Unable to load dynamic library 'C:\php\ext\php_mysql.dll' - Access is denied. in Unknown on line 0
Here's the code of jokes.php
Any ideas? I really want to get through this book!!PHP Code:<?php
error_reporting(E_ALL);
echo 'debug 1<br />';
?>
<body>
<?php
echo 'debug 2<br />';
if (isset($_GET['addjoke'])): // User wants to add a joke
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<label>Type your joke here:<br />
<textarea name="joketext" rows="10" cols="40">
</textarea></label><br />
<input type="submit" value="SUBMIT" />
</form>
<?php else: // Default page display
echo 'debug 3<br />';
//Connect to the database server
$dbcnx = mysql_connect('localhost', 'root', 'mypsswrd') or die(mysql_error());
if (!$dbcnx) {
exit('<p>Unable to connect to the ' .
'database server at this time.</p>');
}
echo 'debug 4<br />';
//Select the jokes database
if (!@mysql_select_db('test')) {
exit('<p>Unable to locate the joke ' .
'database at this time.</p>');
}
echo 'debug 5<br />';
//If a joke has been submitted,
//add it to the database.
if (isset($_POST['joketext'])) {
$joketext = $_POST['joketext'];
$sql = "INSERT INTO joke SET
joketext='$joketext',
jokedate=CURDATE()";
if (@mysql_query($sql)){
echo '<p>Your joke has been added.</p>';
} else {
echo '<p>Error adding submitted joke: ' .
mysql_error() . '</p>';
}
}
echo 'debug 6<br />';
echo '<p>Here are all the jokes in our database:</p>';
//Request the text of all the jokes
echo $result = @mysql_query('SELECT joketext FROM joke');
if (!$result) {
exit('<p>Error performing query: ' .
mysql_error() . '</p>');
}
//Display the text of each joke in a paragraph
while ($row = mysql_fetch_array($result)) {
echo '<p>' . $row['joketext'] . '</p>';
}
//When clicked, this link will load this page
//with the joke submission form displayed.
echo '<p><a href="' . $_SERVER['PHP_SELF'] .
'?addjoke=1">Add a joke!</a></p>';
endif;
?>
</body>
Thanx!





Bookmarks