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 Like 31 Dislike
Previous forums Next forums
Other forums

Problem displaying "scraped" XML data
I'm basicly having trouble displaying XML data scraped from an URL using cURL.

What the code

* Gridview and Detailsview in UpdatePanel, insert mode problem
I have a GridView and DetailsView working together. When a record from Gridview is selected, Detail

Thought I has this figured out especially after all the help i received?
Cags, Salathe, Daniel helped me with this yesterday, but not sure i took it all in.
I am attempti

Referential Integrity problem when inserting into 2 tables at same time
Hello Everyone,

Im relativity new to PHP and MySQL and i have come up against a problem. i h

Are sessions secure at all?..
I haven't really gotten into yet, but I was just thinking of something weird..

Lets say you h

UL and LI Add Form
The idea I want here is when the user click on a character name from the drop down select bar at the

Struct/union and scope problem!
HI all , I have
Code: in header.h typedef struct Node Link; /* ---------

Help Ordering Arrays
Hi, I have 3 arrays as shown below.

Code: $users = $this->get_latest_users();
$flir

b+ tree
Hi
can every body help me about b+ tree ?(insert & delete)

question about stripslashes and real_escape_string
im cleaning up an old app that I wrote fixing some of the vulernabilities from attacks.

I hav

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash