[thelist] php+mySQL

Mark Joslyn mark.joslyn at solimarsystems.com
Thu May 23 12:36:00 CDT 2002


I have a form that is passing variables to this PHP script to:

	1. Create a database
	2. Create a table in that database
	3. Insert data into the table

The database is created no problem. BUT! The table does not get created. Is
there another way to create a table inside a mySQL database using PHP?

Here is the code:

<?php

// Creating a database

$link = mysql_pconnect("localhost", "db_user", "db_password")
	or exit("Connection could not be made");


if (mysql_create_db("$db_name")) {
	print ("Database created successfully\n");
    	} else {
        printf ("Database already created: %s\n", mysql_error ());
}

// Accessing the database

$db_connect = mysql_select_db("$db_name", $link) or die ("Could not find the
database.");
mysql("CREATE TABLE $db_tablename ($name char(20) NOT NULL,$description
char(50) NOT NULL,$version char(20) NOT NULL)");


mysql("INSERT INTO $db_tablename VALUES ($s_name, $s_description,
$s_version)");
	printf ("<br>Records affected: %d\n", mysql_affected_rows());

?>

Any help would be appreciated.

Thanks,

markJ




More information about the thelist mailing list