PDA

View Full Version : SQL ALTER TABLE



nightshade
March 26th, 2005, 04:15 PM
Hi,

I am using the ALTER TABLE function to add a new colomn to my table in MS Access.
I have absolutely no trouble with:

$sql = "ALTER TABLE downloads ADD ".$file_x." varchar(3)";

But this new column has a text datatype. I need one that only takes numerical values. I have tried:

$sql = "ALTER TABLE downloads ADD ".$file_x." int(3)";
$sql = "ALTER TABLE downloads ADD ".$file_x." integer(3)";
$sql = "ALTER TABLE downloads ADD ".$file_x." numeric(3,0)";

but with no effect.

Any ideas?

T-O
March 27th, 2005, 03:38 AM
int is good.

are you sure $file_x is defined right?


$string=query($sql);

msql_query($string);

binime
March 27th, 2005, 03:50 AM
Hi,

I am using the ALTER TABLE function to add a new colomn to my table in MS Access.
I have absolutely no trouble with:

$sql = "ALTER TABLE downloads ADD ".$file_x." varchar(3)";

Any ideas?



$sql = "ALTER TABLE `downloads` ADD `".$file_x."` INT( 5 ) NOT NULL ;";

mysql_query($sql) or die(mysql_error());

nightshade
March 27th, 2005, 01:09 PM
Nope, still no luck. I am using MS Access so it is odbc. I get this error:

Warning: odbc_exec(): SQL error: [Microsoft][ODBC Microsoft Access Driver] Syntax error in ALTER TABLE statement., SQL state 37000 in SQLExecDirect in c:\www\download\download.php on line 39

with this code:

$file_x = "file_".$max;

if ($max == $count) {

$sql = "ALTER TABLE `downloads` ADD `".$file_x."` INT( 3 ) NOT NULL;";
$do_it = odbc_exec($connect, $sql) or die ('Problem in SQL');
$sql = "UPDATE max SET max=".$max;
$do_it = odbc_exec($connect, $sql);
$sql = "UPDATE downloads SET downloads='" .$count. "', " .$file_download. "='" .$new_record. "' WHERE ID=".$user;
$do_it = odbc_exec($connect, $sql);
?><body onload="window.location='download/<? echo $file; ?>.zip'"></body><?
}