I've copied my code at the bottom. If I comment out the CREATE statement and the INSERT statements and the part where I try to read the table and print out the results, and just run it with the $link = mysql_connect ($hostname, $username, $password); statement, I get:
start
end
as my output with no errors, so to me it looks like it connecting to the database okay, but the CREATE statment is not working.
Here's my code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Database connect</title>
</head>
<body>
<br>start
<?php
// fill the information to variables:
$hostname = "localhost";
$username = "myusername";
$password = "mypassword";
$dbname = "mydatebasename";
// connect to the database host, you can use "localhost" instead of $hostname, if the mysql server is the same machine as your web-server:
$link = mysql_connect ($hostname, $username, $password);
// create table
CREATE TABLE bibleverse (
id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
verse TEXT DEFAULT NULL,
chapter VARCHAR(55) DEFAULT NULL
)
// build table
INSERT INTO verse VALUES (1,'Let us not give up meeting together, as some are in the habit of doing, but let us encourage one another - and all the more as you see the Day approaching.','Hebrews 10:25');
INSERT INTO verse VALUES (2,'My mouth will speak words of wisdom; the utterance from my heart will give understanding.','Psalms 49:3');
INSERT INTO verse VALUES (3,'In the house of the wise are stores of choice food and oil, but the foolish man devours all he has.','Proverbs 21:20');
INSERT INTO verse VALUES (4,'Woe to the rebellious children, says the Lord, Who take counsel, but not of Me, And who devis plans, but not of My spirit, That they may add to sin.','Isaiah 30:1');
INSERT INTO verse VALUES (5,'Train up a child in the way he should go, and when he is old, he will not depart from it. The rich rule over the poor and the Borrower is servant to the Lender.','Proverbs 22:6-7');
// query the database: select all the records in table "verse":
$query = mysql_db_query($dbname,"select * from verse;") or die("Query failed");
// retrieve the results: this retrieves the first record:
$result = mysql_fetch_object ($query);
while ($row = mysql_fetch_row($result)) {
if (mysql_errno()) {
die("<br>".mysql_errno().": ".mysql_error()."<br>");
}
foreach ($row as $column) {
echo "<br>$column";
}
echo "<br>";
}
// close the database connection
mysql_close ($link);
?>
<br>end
</body>
</html>