Php fails to create a table, but no error is reported. solve PHPcode & lt ;? Php connection data $ conmysql_connect (& quot; localhost & quot;, & quot; root & quot;, & quot; welcome123 & quot;) ordie (& quot; unable to connect to database & quot ;. mysql_err php fails to create a table, but no error is reported.
PHP code
The page displays "no table", but the table should be created after the execution. I will refresh the page and still display "no table". can you please take a look at the Shenma problem?
------ Solution --------------------
Try:
PHP code
// Connect data $ con = mysql_connect ("localhost", "root", "welcome123") or die ("unable to connect to database ". mysql_error (); // Determine whether the my_project database $ existDB = mysql_select_db ("my_project", $ con); // echo "no my_project database"; if (! $ ExistDB) {// Create a DATABASE $ cdatabseSql = "Create DATABASE my_project"; mysql_query ($ cdatabseSql, $ con); mysql_select_db ("my_project", $ con ); // select database} else {echo "with database";} // Determine whether the sendmail table exists $ row = mysql_query ("show tables"); $ database = array (); $ finddatabase = "sendmail"; while ($ result = mysql_fetch_array ($ row, MYSQL_ASSOC) {$ database [] = $ result ['Tables _ in_test '];} unset ($ result, $ row); if (! In_array ($ finddatabase, $ database) {echo "no TABLE"; $ ctableSql = "Create TABLE sendmail (id int AUTO_INCREMENT primary key, tomail nvarchar (50 ), subject nvarchar (50), message text) "; mysql_query ($ ctableSql, $ con) ;}else {echo" ";}die ();
------ Solution --------------------
Try it like this,
PHP code
If (! $ ExistDB) {// Create a DATABASE $ cdatabseSql = "Create DATABASE my_project"; mysql_query ($ cdatabseSql, $ con); mysql_select_db ("my_project", $ con ); // add one sentence and select the database }............ // Determine whether the sendmail table exists $ row = mysql_list_tables ("my_project"); $ database = array (); $ finddatabase = "sendmail "; while ($ result = mysql_fetch_array ($ row) {$ database [] = $ result [0];} unset ($ result, $ row );