plodos Posted August 8, 2008 Share Posted August 8, 2008 codes... $total_id = mysql_query("SELECT * FROM 'PERSON'"); $num_rows = mysql_num_rows($total_id); $num_rows++; $sql = "select 'committee_id' from 'committee' where 'name'='$committee'"; $id = mysql_query($sql); $result = mysql_fetch_assoc($id); foreach ($result as $v) { $k=$v; } $count_commit = $k; errors Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/public_html/committees/add.php on line 19 Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/public_html/committees/add.php on line 24 Warning: Invalid argument supplied for foreach() in /home/public_html/committees/add.php on line 25 How can I solve these errors? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 8, 2008 Share Posted August 8, 2008 $total_id = mysql_query("SELECT * FROM 'PERSON'") or die(mysql_error()); I can guarantee that you'll get an error. Show us what it is (although I secretly know what the problem is). Quote Link to comment Share on other sites More sharing options...
plodos Posted August 8, 2008 Author Share Posted August 8, 2008 error is 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 ''PERSON'' at line 1 sql codes CREATE TABLE `person` ( `person_id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `title` VARCHAR(20) NOT NULL, `fname` VARCHAR( 40 ) NOT NULL , `lname` VARCHAR( 40 ) NOT NULL , `email` VARCHAR( 128 ) NOT NULL , `country` VARCHAR( 128 ) NOT NULL , `university` TEXT NOT NULL, `university_dept` TEXT NOT NULL, `phone` VARCHAR(40) NOT NULL, `fax` VARCHAR(40) NOT NULL, `research_field` TEXT NOT NULL, `address` TEXT NOT NULL, `date` DATETIME ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci; CREATE TABLE `committee` ( `committee_id` SMALLINT NOT NULL AUTO_INCREMENT PRIMARY KEY , `name` TEXT NOT NULL ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci; CREATE TABLE `join_person_committee` ( `person_id` INT NOT NULL , `committee_id` SMALLINT NOT NULL , PRIMARY KEY ( `person_id` , `committee_id` ) ) ENGINE = MYISAM ; What is wrong...? Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted August 8, 2008 Share Posted August 8, 2008 $total_id = mysql_query("SELECT * FROM 'PERSON'"); To $total_id = mysql_query("SELECT * FROM `PERSON`"); WRONG type of quotes around person Quote Link to comment Share on other sites More sharing options...
Jabop Posted August 8, 2008 Share Posted August 8, 2008 Remove the single quotes or add tilde quotes (`) around it Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 8, 2008 Share Posted August 8, 2008 Just remove the quotes. Don't use backticks, because not all SQL servers support them so if you had to switch...you'd be stuck. Just remove the ' '. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted August 8, 2008 Share Posted August 8, 2008 Just remove the quotes. Don't use backticks, because not all SQL servers support them so if you had to switch...you'd be stuck. Just remove the ' '. and what if you have a column with the same name as a function? Quote Link to comment Share on other sites More sharing options...
Jabop Posted August 8, 2008 Share Posted August 8, 2008 Just remove the quotes. Don't use backticks, because not all SQL servers support them so if you had to switch...you'd be stuck. Just remove the ' '. How sure of that are you? I'm pretty sure that those specify literals in sql and are a safe measure and good practice... Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 8, 2008 Share Posted August 8, 2008 Just remove the quotes. Don't use backticks, because not all SQL servers support them so if you had to switch...you'd be stuck. Just remove the ' '. and what if you have a column with the same name as a function? You rename the column. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 8, 2008 Share Posted August 8, 2008 Just remove the quotes. Don't use backticks, because not all SQL servers support them so if you had to switch...you'd be stuck. Just remove the ' '. How sure of that are you? I'm pretty sure that those specify literals in sql and are a safe measure and good practice... It's a MySQL only thing. PostgreSQL throws some along the lines of: ERROR: operator does not exist: ` character HINT: No operator matches the given name and argument type(s). You may need to add explicit type casts. >_> Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted August 8, 2008 Share Posted August 8, 2008 Well, he isn't using PostgreSQL. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 8, 2008 Share Posted August 8, 2008 Don't use backticks, because not all SQL servers support them so if you had to switch...you'd be stuck. =P Quote Link to comment Share on other sites More sharing options...
plodos Posted August 8, 2008 Author Share Posted August 8, 2008 sql CREATE TABLE `person` ( `person_id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `title` VARCHAR(20) NOT NULL, `fname` VARCHAR( 40 ) NOT NULL , `lname` VARCHAR( 40 ) NOT NULL , `email` VARCHAR( 128 ) NOT NULL , `country` VARCHAR( 128 ) NOT NULL , `university` TEXT NOT NULL, `university_dept` TEXT NOT NULL, `phone` VARCHAR(40) NOT NULL, `fax` VARCHAR(40) NOT NULL, `research_field` TEXT NOT NULL, `address` TEXT NOT NULL, `date` DATETIME ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci; CREATE TABLE `committee` ( `committee_id` SMALLINT NOT NULL AUTO_INCREMENT PRIMARY KEY , `name` TEXT NOT NULL ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci; CREATE TABLE `join_person_committee` ( `person_id` INT NOT NULL , `committee_id` SMALLINT NOT NULL , PRIMARY KEY ( `person_id` , `committee_id` ) ) ENGINE = MYISAM ; insert into committee values('10','Electrical'); insert into committee values('9','Industrial'); insert into committee values('8','Engineering'); insert into committee values('7','Processing'); insert into committee values('6','Mathematics'); insert into committee values('5','Biological'); insert into committee values('4','Computer'); insert into committee values('3','Computational'); insert into committee values('2','Sciences'); insert into committee values('1','Technology'); query SELECT committee_id FROM committee WHERE name = `Electrical` LIMIT 0 , 30 MySQL #1054 - Unknown column 'Electrical' in 'where clause' query has a problem? dou you know why? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 8, 2008 Share Posted August 8, 2008 Use ' ' and not ` ` for that... Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted August 8, 2008 Share Posted August 8, 2008 use single quotes for values, and use back ticks for column/table names Quote Link to comment Share on other sites More sharing options...
plodos Posted August 8, 2008 Author Share Posted August 8, 2008 sql CREATE TABLE `person` ( `person_id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `title` VARCHAR(20) NOT NULL, `fname` VARCHAR( 40 ) NOT NULL , `lname` VARCHAR( 40 ) NOT NULL , `email` VARCHAR( 128 ) NOT NULL , `country` VARCHAR( 128 ) NOT NULL , `university` TEXT NOT NULL, `university_dept` TEXT NOT NULL, `phone` VARCHAR(40) NOT NULL, `fax` VARCHAR(40) NOT NULL, `research_field` TEXT NOT NULL, `address` TEXT NOT NULL, `date` DATETIME ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci; CREATE TABLE `committee` ( `committee_id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `name` TEXT NOT NULL ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci; CREATE TABLE `join_person_committee` ( `person_id` INT NOT NULL , `committee_id` SMALLINT NOT NULL , PRIMARY KEY ( `person_id` , `committee_id` ) ) ENGINE = MYISAM ; insert into committee values(`10`,`Electrical`); insert into committee values(`9`,`Industrial`); insert into committee values(`8`,`Engineering`); insert into committee values(`7`,`Processing`); insert into committee values(`6`,`Mathematics`); insert into committee values(`5`,`Biological`); insert into committee values(`4`,`Computer`); insert into committee values(`3`,`Computational`); insert into committee values(`2`,`Sciences`); insert into committee values(`1`,`Technology`); error SQL : INSERT INTO committee VALUES ( `10` , `Electrical` ); MySQL : #1054 - Unknown column '10' in 'field list' I changed all of them " ' " , still there is a problem? Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted August 8, 2008 Share Posted August 8, 2008 `10` , `Electrical` To '10' , 'Electrical' Like I said before: values use single quotes tables/columns use back ticks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.