Throdne Posted March 28, 2009 Share Posted March 28, 2009 Hello, i'm having a little problem with me database installer script. <?php /* // Coded By Throdne. */ $query["users"] = " CREATE TABLE users( cid integer NOT NULL AUTO_INCREMENT PRIMARY KEY , userid int( 100 ) NOT NULL , user varchar( 100 ) NOT NULL , pass varchar( 100 ) NOT NULL , level int( 1 ) NOT NULL , email varchar( 100 ) NOT NULL ) "; $query["posts"] = " CREATE TABLE posts( post_id integer NOT NULL AUTO_INCREMENT PRIMARY KEY , post_userid int ( 100 ) NOT NULL , post_user varchar( 100 ) NOT NULL , post_date varchar( 11 ) NOT NULL , post_title varchar( 100 ) NOT NULL , post_message varchar( 65000 ) NOT NULL , post_commentnumbers int( 10 ) NOT NULL ) "; $query["patch"] = " CREATE TABLE patch( patch_id integer NOT NULL AUTO_INCREMENT PRIMARY KEY , patch_userid int ( 100 ) NOT NULL , patch_number varchar( 10 ) NOT NULL , patch_date varchar( 11 ) NOT NULL , patch_message varchar( 65000 ) NOT NULL , patch_commentnumbers int( 10 ) NOT NULL ) "; function query_install() { global $con; global $query; foreach($query as $querycom) { $querytablename = array_keys($querycom); mysql_query($querycom, $con) or die('Cannot execute! (' . $querytablename . ' Table)'); echo('Table created! (' . $querytablename . ')<br />'); }; } ?> when i run this, i get this error message. Warning: array_keys() [function.array-keys]: The first argument should be an array in C:\xampp\htdocs\install\create.php on line 44 Cannot execute! ( Table) line 44 is " $querytablename = array_keys($querycom);" What i'm going for works, but when I want to show the DB tables name, to state that it is installed. I get an error message. Maybe i have it written wrong. O by the way, this file is include() in another file, "install.php". this script is ran after my installed checker script. I know that works, I tried it out. but when i put in the table's name in the output i get this. Link to comment https://forums.phpfreaks.com/topic/151482-error-message-with-array_keys/ Share on other sites More sharing options...
ratcateme Posted March 28, 2009 Share Posted March 28, 2009 try foreach($query as $querytablename => $querycom) { mysql_query($querycom, $con) or die('Cannot execute! (' . $querytablename . ' Table)'); echo('Table created! (' . $querytablename . ')<br />'); } also you don't need the ; at the end of your foreach Scott. Link to comment https://forums.phpfreaks.com/topic/151482-error-message-with-array_keys/#findComment-795636 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.