tags:

views:

51

answers:

1

Hi guys, I have written a code that should check weather there is a table called imei.$addimei and, if not, create it...

$userdatabase = mysqli_connect('localhost', 'root', 'marina', 'imei');
...
$result = mysqli_query($userdatabase, "SELECT * FROM imei".$addimei."" );
if ( !$result ) { echo('creating table...'); /// if no such table, make one!

mysql_query ( $userdatabase,
'CREATE TABLE imei'.$addimei.'(
ID int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(ID),

EVENT varchar(15),
TIME varchar(25),
FLD1 varchar(35),
FLD2 varchar(35),
IP varchar(25),
)' );
}

Yet the CREATE TABLE somehow doesn't seem to work. Warning: mysql_query() expects parameter 1 to be string, object given in C:\xampp\xampp\htdocs\mobi\mainmenu.php on line 564

Any idea's what wrong? Thanks!

+1  A: 

edit:

http://pt.php.net/manual/en/function.mysql-query.php

mysql_query (
'CREATE TABLE imei'.$addimei.'(
ID int NOT NULL AUTO_INCREMENT PRIMARY KEY,

EVENT varchar(15),
TIME varchar(25),
FLD1 varchar(35),
FLD2 varchar(35),
IP varchar(25))', $userdatabase );

EDIT: Hello, had to go yesterday, sorry... Your connection is mysqli, see EXAMPLE 2 in this page:

http://php.net/manual/en/mysqli.query.php

acmatos
same :) Warning: mysql_query() expects parameter 1 to be string, object given
edited answer again, mysql_query argument order! ;-)
acmatos
still pops an error :)Warning: mysql_query() expects parameter 2 to be resource, object given
well, don't send the $userdatabase. from php.net: [If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If no connection is found or established, an E_WARNING level error is generated.]
acmatos
if I don't use the $userdatabase in the query, it gives Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\xampp\htdocs\mobi\mainmenu.php on line 563Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\xampp\xampp\htdocs\mobi\mainmenu.php on line 563
Thanks for the input, I tired placing the $userdatabase in the beginning of the query ( as in that example ), as well as in the end like above, but it still pops out errors... hmm...
@user296516: what error is it now? can you be sure the connection is working by executing a SELECT statement that returns something?
acmatos
yes, the connection is working. its both selecting, inserting, etc.the error now is Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\xampp\htdocs\mobi\mainmenu.php on line 563Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\xampp\xampp\htdocs\mobi\mainmenu.php on line 563
your error mentions mysql_query and your connection is mysqli, you should be doing something like $mysqli->query("CREATE TABLE table_name(...)");
acmatos
really! i had lost that 'i' on the end. LOL :)))but the funny thing now is that it does not give an error, yet it does not create the table either...
i'm sorry, my bad now... i gave you the code from object oriented (example #1) and it should be from the procedural one (example #2): mysqli_query($userdatabase, "CREATE TABLE table_name(...)"); also, notice you can check for table existence @ mysql query: create table if not exists table_name (...)
acmatos
now the mysqli_error(); shows - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 9
YES! GOT IT! THE PROBLEM WAS IN ',' AFTER THE LAST IP varchar(25), :)))
yeah, now that the query was actualy being executed it threw the only error we've missed! nice! ;-)
acmatos