Re: why do this not create a database?
From: Paul Barfoot (Paul_at_theglobalfamily.fsworld.co.uk)
Date: 10/02/04
- Previous message: Dicki Smits: "why do this not create a database?"
- In reply to: Dicki Smits: "why do this not create a database?"
- Next in thread: Dicki Smits: "Re: why do this not create a database?"
- Reply: Dicki Smits: "Re: why do this not create a database?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 2 Oct 2004 17:03:58 +0100
Hi Dicki
Your code does create the table - it is your INSERT queries that are wrong.
They should read INSERT INTO not INSERT TO.
Here is my version of what you are trying to achieve with a few pointers:
<html>
<title>hello world</title>
<body>
<?php
$host = "localhost";
$user = "root";
$pswd = "";
/* only need to connect and select database once */
mysql_connect($host,$user,$pswd) or die(mysql_error());
mysql_select_db ("project");
/* code to delete the current version of the nieuws table */
mysql_query ("DROP TABLE IF EXISTS nieuws");
/* Note date field should have used DATE type */
mysql_query ("CREATE TABLE IF NOT EXISTS nieuws ( id integer, title
varchar(255), date DATE, text blob)");
/* Note format of DATE type - YYYY/MM/DD or even YYYY-MM-DD */
mysql_query ("INSERT INTO nieuws VALUES ( 1,'tweede
cursus','2004/05/05','een nieuwe cursus...')");
mysql_query ("INSERT INTO nieuws VALUES (2,'tweede cursus','2004/05/05','een
nieuwe cursus...')");
$result = mysql_query("SELECT * FROM nieuws WHERE id=1");
/* code to display the contents of the last query as a table with field
names as the table headers */
$results=mysql_num_rows($result);
if (!$results==0) {
echo "<p>$results rows returned.</p>\n";
echo "<table border=1>\n";
// get column metadata for column headings
echo "<tr>\n";
$i = 0;
while ($i < mysql_num_fields ($result)) {
$meta = mysql_fetch_field ($result);
if (!$meta) {
echo "No information available<BR>\n";
}
echo "<td><b>$meta->name</b></td>\n";
$i++;
}
echo "</tr>\n";
while ($row = mysql_fetch_row ($result)) {
echo "<tr>\n";
foreach ($row as $value) {
echo "<td>$value</td>\n";
}
echo "</tr>\n";
}
echo "</table>\n";
mysql_free_result ($result);
}
?>
</body>
</html>
--
Paul Barfoot
"Dicki Smits" <dicki@absoluut.org> wrote in message
news:ac5e367f.0410012334.22168a19@posting.google.com...
>I am learning php-mysql but I typed the following into my notepad but
> it seems not to work. The page will be shown correct in the brouwser
> but it don't create a databse ????
>
> I use easyphp packet. php 4.3.3 ,mysql 4.0.15 . and apache 1.3.27
>
> any help would be great.
> greatings Dicki Smits
>
> ****
> <html>
> <title>hello world</title>
>
> <body>
>
> <?php
>
> $host = "localhost";
> $user = "root";
> $pswd = "";
>
> mysql_connect($host,$user,$pswd) or die(mysql_error());
> mysql_select_db ("fotoboek");
> mysql_query ("create table nie1uws ( id integer,
> title varchar(255),
> date integer,
> text blob)");
>
> mysql_connect($host,$user,$pswd) or die(mysql_error());
> mysql_select_db ("fotoboek");
> mysql_query ("INSERT TO nieuws values ( 1,
> 'tweede cursus',
> 5/5/2004,
> 'een nieuwe cursus...')");
>
> mysql_query ("INSERT TO nieuws values (2,'tweede
> cursus',5/5/2004,'een nieuwe cursus...')");
> mysql_connect($host,$user,$pswd) or die(mysql_error());
> mysql_select_db ("fotoboek");
> $result = mysql_query("select * from nieuws where id=1");
> echo $result
>
> ?>
> Waarom zie ik niet dat er geen database is aangemaakt?
> </body>
> </html>
- Previous message: Dicki Smits: "why do this not create a database?"
- In reply to: Dicki Smits: "why do this not create a database?"
- Next in thread: Dicki Smits: "Re: why do this not create a database?"
- Reply: Dicki Smits: "Re: why do this not create a database?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]