Simple MySQL script is not working
Posted on
16th Feb 2014 07:03 pm by
admin
Hey guys,
Just familiarizing myself with PHP and MySQL. I am following along in the O'Reilly book that addresses both topics and has the platypus on the cover.
At any rate, I tried typing in chapter 6 exercise 1 and the script did not work. I then downloaded the example code from the books website and found out what I typed was identical and actually tried the downloaded script and had THAT not work.
Other PHP scripts are working, so I know it's not the system. For instance phpinfo.php does it's thing, as do my other scripts so far.
Here is the code from the downloaded example:
Code: [Select]<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html401/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Wines</title>
</head>
<body>
<pre>
<?php
// (1) Open the database connection
$connection = mysql_connect("localhost","fred","shhh");
// (2) Select the winestore database
mysql_select_db("winestore", $connection);
// (3) Run the query on the winestore through the connection
$result = mysql_query ("SELECT * FROM
wine", $connection);
// (4) While there are still rows in the result set, fetch the current
// row into the array $row
while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
// (5) Print out each element in $row, that is, print the values of
// the attributes
foreach ($row as $attribute)
print "{$attribute} ";
// Print a carriage return to neaten the output
print "n";
}
?>
</pre>
</body>
</html>
I am running a Mac OS X 10.6 (Snow Leopard) system and have put the script in the same place that my other PHP scripts are working : Mac HD -> Library -> WebServer -> Documents
This simple script is meant to access a MySQL db and print it's contents in a web browser. Obviously the db login here is fake. But in the 'real' script I have tried a user that should have rights and even tried it with root which I KNOW has rights. I am able to access the db from the command line interpreter using both the user and with root. The script and the browser are running locally on my machine and being served by apache (which has been restarted both with apachectl and with the GUI tools).
Thanks!
No comments posted yet
Your Answer:
Login to answer
340
31
Other forums
Needing Youtube thumb nail fix.
I have a script on a site that pulls in you-tube videos,
The problem is, that the thumb nails for
Generating unique numbers using php
Hi,
I need help in generating unique number using php.I tired using rand() in php.But, by using r
values in array being escaped
I would like to submit some values - back to the same form for checking before processing...
Simple Scraper... Weird Output
Okay, maybe I just need a Blue Monster and some sleep, but....
I'm scraping a ringtone site
textfield unchanged
hi,
i want my form to know whether its textbox is unchange or not.
if($textbox == 'unchang
Chat Box in PHP
I was thinking in doing a Chat Box in PHP. For that I would use a form with two fields, Nick and Mes
PHP4 to PHP5 Conversion
Hi Everyone,
I am working on a site that is built up on PHP4 and each page is being started f
need help with this contact form
I made this form and I need it to read the data and write the data to a table and its not working ca
Do not allow posting of whitespace
Currently the script below works if the user does not type a name/message, but if i create a whitesp
string to currency format
Hi guys...
Actually I chunk out some data from txtfile and one of the data contains amount va