PDA

View Full Version : PHP/MYSQL syntax issues


bluemicrobyte
12-26-2005, 8:26 PM
So I need to do the following stuffs to my MySQL table but its giving me errors about it not being formatted correctly. Please help!!


"CREATE TABLE " . LOGS_TABLE . " (
id_log MEDIUMINT(10) NOT NULL DEFAULT '0' AUTO_INCREMENT,
mode VARCHAR(50) NULL DEFAULT '',
topic_id MEDIUMINT(10) NULL DEFAULT '0',
user_id MEDIUMINT(8) NULL DEFAULT '0',
username VARCHAR(255) NULL DEFAULT '',
user_ip CHAR(8) DEFAULT '0' NOT NULL,
time INT(11) NULL DEFAULT '0',
PRIMARY KEY (id_log))";

-------------------------------------------------

"CREATE TABLE " . LOGS_CONFIG_TABLE . " (
config_name varchar(255) NOT NULL,
config_value varchar(255) NOT NULL,
PRIMARY KEY (config_name))";

------------------------------------------------

"INSERT INTO " . LOGS_CONFIG_TABLE . " (
config_name, config_value)
VALUES ('all_admin', 0)";

----------------------------------------------

"ALTER TABLE " . USERS_TABLE . "
ADD user_view_log TINYINT NOT NULL DEFAULT '0'";
break;

case 'postgresql':

--------------------------------------

"CREATE TABLE " . LOGS_TABLE . " (
id_log SERIAL NOT NULL PRIMARY KEY,
mode VARCHAR(50) DEFAULT '',
topic_id INT4 DEFAULT 0,
user_id INT4 DEFAULT 0,
username VARCHAR(255) DEFAULT '',
user_ip CHAR(8) DEFAULT '0' NOT NULL,
time INT4 DEFAULT 0 )";

----------------------------------------------

"CREATE TABLE " . LOGS_CONFIG_TABLE . " (
config_name varchar(255) NOT NULL PRIMARY KEY,
config_value varchar(255) NOT NULL )";

-------------------------------------------------

"INSERT INTO " . LOGS_CONFIG_TABLE . " (
config_name, config_value )
VALUES ( 'all_admin', 0 )";

---------------------------------------

"ALTER TABLE " . USERS_TABLE . "
ADD user_view_log INT2 NOT NULL DEFAULT 0";

Greyscale
12-26-2005, 10:02 PM
Odd ammount of quotes there....


$query = "CREATE TABLE logs_table (
id_log MEDIUMINT(10) NOT NULL DEFAULT '0' AUTO_INCREMENT,
mode VARCHAR(50) NULL DEFAULT '',
topic_id MEDIUMINT(10) NULL DEFAULT '0',
user_id MEDIUMINT(8) NULL DEFAULT '0',
username VARCHAR(255) NULL DEFAULT '',
user_ip CHAR(8) DEFAULT '0' NOT NULL,
time INT(11) NULL DEFAULT '0',
PRIMARY KEY (id_log))";

mysql_query ($query);


The code at the bottom is a function that takes the inputted query and runs it with mySQL.

It would help if you could say, more in-depth like, what you are trying to accieve with the code. Helps. Also, try using PHPmyAdmin for debug purposes.

bluemicrobyte
12-26-2005, 10:07 PM
I do use PHPmyAdmin

This is part of a mod for my forum -- the files have already been modified by an automated script on my forum, but the MySQL needs to be done manually for this mod. I'm basically just following step by step instructions and the step I'm stuck on is "do this to the MySQL database" because its giving me errors.

I would appreciate it if someone could either edit all of the queries so they work, or tell me what I have to do to change them so that they work with PHPmyAdmin. I know very little about MySQL, and a small amount about PHP.

Greyscale
12-26-2005, 11:53 PM
1) What forum software are you using
2) What is the mod supposed to do.

There is probally a easier way to do this, but:


CREATE TABLE LOGS_TABLE (
id_log MEDIUMINT(10) NOT NULL DEFAULT '0' AUTO_INCREMENT,
mode VARCHAR(50) NULL DEFAULT '',
topic_id MEDIUMINT(10) NULL DEFAULT '0',
user_id MEDIUMINT(8) NULL DEFAULT '0',
username VARCHAR(255) NULL DEFAULT '',
user_ip CHAR(8) DEFAULT '0' NOT NULL,
time INT(11) NULL DEFAULT '0',
PRIMARY KEY (id_log))

-------------------------------------------------

CREATE TABLE LOGS_CONFIG_TABLE (
config_name varchar(255) NOT NULL,
config_value varchar(255) NOT NULL,
PRIMARY KEY (config_name))

------------------------------------------------

INSERT INTO LOGS_CONFIG_TABLE (
config_name, config_value)
VALUES ('all_admin', 0)

----------------------------------------------

ALTER TABLE USERS_TABLE ADD user_view_log TINYINT NOT NULL DEFAULT '0'



Use ONLY the above querys in PHPmyAdmin, and you should be fine. It should work, but it might not. Just test it once you're done.

bluemicrobyte
12-27-2005, 1:32 AM
the forum is running off of phpbb and the mod files are attatched (in a zip file since theres multiple files -- it comes with an automated MySQL table modifying script, but it wasnt working so I copied the PHP query command things and still had trouble) The mod is supposed to log the actions of moderators.

I shall try the queries you posted and update this post shortly.

edit: first one gave me an error

Error
SQL query:

CREATE TABLE LOGS_TABLE(id_log MEDIUMINT( 10 ) NOT NULL DEFAULT '0' AUTO_INCREMENT ,
MODE VARCHAR( 50 ) NULL DEFAULT '',
topic_id MEDIUMINT( 10 ) NULL DEFAULT '0',
user_id MEDIUMINT( 8 ) NULL DEFAULT '0',
username VARCHAR( 255 ) NULL DEFAULT '',
user_ip CHAR( 8 ) DEFAULT '0' NOT NULL ,
time INT( 11 ) NULL DEFAULT '0',
PRIMARY KEY ( id_log )
)


MySQL said: http://70.98.111.60:2082/3rdparty/phpMyAdmin/themes/green_orange/img/b_help.png (http://dev.mysql.com/doc/mysql/en/Error-returns.html)

#1067 - Invalid default value for 'id_log'

Hawthorne
12-27-2005, 2:00 AM
Hmm, well seeing as I'm not intocoding, I thinkyou'd better seek advice from NeoX or AJ or someone thatruns the current ORG Network sites :)