PDA

View Full Version : I cannot create a table in php using sql


tedpottel
04-07-2005, 03:49 PM
Hi,

I'm trying to do this on my web page

// load values
$sql_string="CREATE TABLE `test` (`myid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT , INDEX (`myid`))";
if (!$results=mysql_query($sql_string,$dblink))
die("could not query data");
die("Constructed databa");

the ouput is could not create query.

help!!!!

Ted

Silmaril8n
04-07-2005, 04:43 PM
Did you make your database connection before that code? Did it connect?

tedpottel
04-08-2005, 12:11 PM
Hi, thank you for replying,
here is all the code

<?php


if (!($dblink = mysql_connect("localhost","superme","********")))
{
die("connect");
}


if (!($dbconn = mysql_select_db("superme_mydatabase",$dblink)))
{
die("select");
}


// load values
$sql_string="CREATE TABLE `test` (`myid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT , INDEX (`myid`))";
if (!$results=mysql_query($sql_string,$dblink))
die("could not query data");
die("Constructed databa");

?>

The output is could not query data,
so the connnect is working.

do you have any idears?

Ted

Silmaril8n
04-08-2005, 12:40 PM
I'm still thinking it's a connect issue. The query is correct, so the reason that it can't be executed is probably because there is no database connected.

You need to specify a user to that has the rights to the database.

if (!($dblink = mysql_connect("localhost","superme_user","********")))
{
die("connect");
}

garett55
05-02-2005, 11:29 AM
What version of php are you using?
I have only used the latest version and in my code

$mysql_query() only takes one parameter which is the string you are using to query

if that doesn't work try taking out the dies and seeing what error message sql is sending back

also for slightly neater code you can use $dblink = @mysql_connect(XXX,XXX,XXX) or die("ERROR MSG")