Cody Elhard Cody Elhard - 6 months ago 13
PHP Question

PHP/mysql error

I am trying to make a script that will a table to the database('alphacrm') that has already been created.My error is that the echo line near the very bottom will not display, and no table is created to my database. I have already verified that $dbSuccess is true, not sure where I went wrong after that.I did try to see if it was correctly concatenated, but that did not seem to be the issue. If you spot my mistake it would be greatly appreciated!

if ($dbSuccess) {

$createCoyTable_SQL = "CREATE TABLE alphacrm.tCompany ( ";
$createCoyTable_SQL .= "ID INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY ";
$createCoyTable_SQL .= "preName VARCHAR( 50 ) , ";
$createCoyTable_SQL .= "Name VARCHAR( 250 ) NOT NULL, ";
$createCoyTable_SQL .= "RegType VARCHAR( 50 ) NULL, ";
$createCoyTable_SQL .= "SreetA VARCHAR( 150 ) NULL, ";
$createCoyTable_SQL .= "SreetB VARCHAR( 150 ) NULL, ";
$createCoyTable_SQL .= "SreetC VARCHAR( 150 ) NULL, ";
$createCoyTable_SQL .= "Town VARCHAR( 150 ) NULL, ";
$createCoyTable_SQL .= "County VARCHAR( 150 ) NULL, ";
$createCoyTable_SQL .= "Postcode VARCHAR( 150 ) NULL, ";

$createCoyTable_SQL .= "COUNTRY VARCHAR( 250 ) NOT NULL ";
$createCoyTable_SQL .= ")";

if (mysql_query($createCoyTable_SQL)) {
echo "Creation of TABLE tCompany -- Succesful <br />";
}

$createPersonTable_SQL = "CREATE TABLE alphacrm.tPerson ( ";
$createPersonTable_SQL .= "ID INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY ";
$createPersonTable_SQL .= "Salutation VARCHAR( 20 ) , ";
$createPersonTable_SQL .= "FirstName VARCHAR( 50 ) , ";
$createPersonTable_SQL .= "LastName VARCHAR( 50 ) NOT NULL, ";
$createPersonTable_SQL .= "CompanyID VARCHAR( 11 ) NOT NULL ";
$createPersonTable_SQL .= ")";

if (mysql_query($createPersonTable_SQL)) {
echo "Creation of tPerson table was succesful <br />";
}
}

Answer

Found an error, change this line:

   $createCoyTable_SQL .= "ID INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY ";

to this line:

   $createCoyTable_SQL .= "ID INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY,";

Let me know if that fixed it, meanwhile I am searching for more.

Comments