Forum Moderators: coopster
I've read a lot of manuals but can't see what's wrong.
//make database
mysql_query("CREATE TABLE mydatabase( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), url VARCHAR(30), description VARCHAR(30))")or die("Create table Error: ".mysql_error());
//insert something
mysql_query("INSERT INTO TABLE mydatabase (url,description) VALUES ('hi','database')");
//output table
$result = mysql_query( "SELECT * FROM mydatabase" )
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
print "There are $num_rows records.<P>";
print "<table width=200 border=1>\n";
while ($get_info = mysql_fetch_row($result)){
print "<tr>\n";
foreach ($get_info as $field)
print "\t<td><font face=arial size=1/>$field</font></td>\n";
print "</tr>\n";
}
print "</table>\n";
addded: If anybody knows function library's that handle Mysql queries specially for beginners and idiots please let me know.
mysql_query("INSERT INTO TABLE mydatabase (id,url,description) VALUES ('','hi','database')");
Added: phpMyAdmin is very helpful for finding problems. It this case you could have simply done an insert via phpMyAdmin and then they give you the exact query used. You then copy that to your script and alter where needed.
CREATE TABLE `mytable` (
`id` INT NOT NULL AUTO_INCREMENT,
`url` VARCHAR( 30 ) NOT NULL ,
`description` VARCHAR( 30 ) NOT NULL ,
PRIMARY KEY ( `id` )
);INSERT INTO `mytable` ( `id` , `url` , `description` )
VALUES (
'', 'hi', 'database'
);
The noticable thing are the use of backquotes and PRIMARY KEY is at the end.