|
Posted by max on 08/14/05 01:48
[snip]
>And it would also help to see the content of $Query after assignment.
>
>This entire query is in wrong syntax. Have a look at CREATE TABLE in the mySQL manual.
I borrowed the output from phpMyAdmin. Just done it again, with a table
name of test, and it created a table called test, and returned -
CREATE TABLE `test` (
`id` SMALLINT( 3 ) NOT NULL AUTO_INCREMENT ,
`firstname` VARCHAR( 255 ) NOT NULL ,
PRIMARY KEY ( `id` )
);
and offered, under "Create PHP code" -
$sql = 'CREATE TABLE `test` ('
. ' `id` SMALLINT(3) NOT NULL AUTO_INCREMENT, '
. ' `firstname` VARCHAR(255) NOT NULL,'
. ' PRIMARY KEY (`id`)'
. ' )';
// What are the ' .' for; line-feeds in phpMyAdmin???
My whole file is -
<?
include("php-lib/connect_inc.php");
$TableName=rand(12345, 99999);
// which I thought would create $TableName with the value from the rand()
print("$TableName<br>");
//To check.
$Query = 'CREATE TABLE $TableName ('
. ' `id` SMALLINT(3) NOT NULL AUTO_INCREMENT, '
. ' `firstname` VARCHAR(255) NOT NULL,'
. ' PRIMARY KEY (`id`)'
. ' )';
$Result=mysql_db_Query ($DBName, $Query, $Link);
print("$Query<br>");
// To print out the $Query. The result of this is
========
24678
CREATE TABLE $TableName ( `id` SMALLINT(3) NOT NULL AUTO_INCREMENT,
`firstname` VARCHAR(255) NOT NULL, PRIMARY KEY (`id`) )
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
resource in blah-blah/create_dbase.php on line 21
====================
$Query="insert into $TableName (id, firstname) values ('5', 'Fred')";
$Result=mysql_db_Query ($DBName, $Query, $Link);
// to insert some test data
$Query="SELECT * FROM $TableName";
$Result=mysql_db_query ($DBName, $Query, $Link);
while ($Row=mysql_fetch_array ($Result))
{
print("<table><tr><td>");
print("$Row[id] $Row[firstname]");
print("</td></tr></table>");
}
// to select the test data and display it.
?>
Navigation:
[Reply to this message]
|