Unable to run query - php

when i run my php page this error show:
Unable to run query:Unknown column 'NUM_OPTIONAL_COLLEGE_COURSE' in 'field list'
$sql ="INSERT INTO MAJOR (`COL_NO`, `DEPT_NO`, `YEAR`, `NUM_OPTIONAL_UNI_COURSE`,
`NUM_MANDATORY_UNI_COURSE`, `NUM_OPTIONAL_COLLEGE_COURSE`,
`NUM_MANDATORY_COLLEGE_COURSE`, `NUM_OPTIONAL_DEPT_COURSE`, `NUM_MANDATORY_DEPT_COURSE`,
`NUM_FREE_COURSE`, `NUM_CUSHIONS_COURSE`, `NUM_OF_CREDIT`)
VALUES('$myq1','$myq2','$myq3','$myq4','$myq5','$myq6','$myq7','$myq8','$myq9',
'$myq10','$myq11','$myq12')";
can you help me in this ?

There is no column named NUM_OPTIONAL_COLLEGE_COURSE in table MAJOR. Re-check your column name, most probably its a spelling mistake.

The Error says it all
Verify NUM_OPTIONAL_COLLEGE_COURSE is the column name in the schema

Most errors occur if you have a column like " NUM_OPTIONAL_COLLEGE_COURSE" (mind the space in front) - use your Database Management System and Copy the name of the column.

Its a database schema error, The error means the column does not exist in table. You have to check out it carefully....You should also check, may be you are connected with wrong database. Once I also faced this type error, and my idiocy , I was runing my query on wrong database.

Related

Cannot insert column containing colon in column name

I am trying to insert a column with column name 00:18:e7:f9:65:a6 with the statement
ALTER IGNORE TABLE tblwifi_information ADD "00:18:e7:f9:65:a6" INT
...but it throws an error:
/* SQL Error (1064): 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 '"00:18:e7:f9:65:a6" INT' at line 1 */
in Heidi SQL. I am using MySQL database.
When I try to add the column manually b going to the structure of the table it works and does not give any error but when I run this statement it does not allow me. How can I solve this?
I just ran your query:
ALTER IGNORE TABLE tblwifi_information ADD "00:18:e7:f9:65:a6" INT
and got the same error. I then ran:
ALTER IGNORE TABLE tblwifi_information ADD `00:18:e7:f9:65:a6` INT
and it worked. Pretty sure you need to change " to `
Fail with double qoutes:
Success with backticks:
use backticks for columnname
change
ALTER IGNORE TABLE tblwifi_information ADD "00:18:e7:f9:65:a6" INT
TO
ALTER IGNORE TABLE tblwifi_information ADD `00:18:e7:f9:65:a6` INT
SQL FIDDLE
To add something to the story, when querying multiple tables, you have to use following expression:
`tablename`.`columnname`
(NOT `tablename.columnname` )
I took me some time to figure it out, so I hope it helps someone :)
Example:
SELECT *
FROM tb_product p
JOIN tb_brand b ON ( `p`.`tb_brand:IDbrand` = `b`.`IDbrand` )
WHERE IDfamily = 2
i dont really know what you are trying to achive here pal.
instead of:
00:18:e7:f9:65:a6
to
00_18_e7_f9_65_a6
then adjust your code to replace ":" to "_" in php or mysql.
in sql:
Replace(table_name, ':', '_');
in PHP:
srt_replace(':','_',$query);

MySQL Error - Unknown column - need to edit

Thanks for reading.
Reading through all the articles on here helped me locate my problem, I'm just not sure how I should edit the code. I still learning.
The message I get is:
SELECT attachid
FROM ilace_attachment WHERE attachtype = 'ads' AND user_id ='6' AND ads_id='1'
MySQL Error : Unknown column 'ads_id' in 'where clause'
Error Number : 1054
This all started after I upgrade my software script to a newer version. I checked the ads_ads in MYSQL and there isn't a colum for ads_id, just one called; id.
I believe the solution to my problem is to change the "ads_id" to just "id". But I'm not sure if thats right or what I should change.
$sql = $ilace->db->query("SHOW TABLE STATUS LIKE '". DB_PREFIX ."ads_ads'");
$ads_id_temp = $ilace->db->fetch_array($sql);
$ads_id=$ads_id_temp['Auto_increment'];
}
else
{
$ads_id=$ilace->GPC['id'];
}
$attachid = $ilace->db->fetch_field(DB_PREFIX . "attachment", "attachtype = '".'ads'."' AND user_id ='".$_SESSION['ilacedata']['user']['userid']."' AND ads_id='".$ads_id."'", "attachid");
Here is the script it runs.
http//wwwWEBSITEcom/campaign.php?id=0&cmd=_create- campaign&1=Advertise+here+for+%245.00+per+1000+views&2=Targeted+AdTITLENAME+adverts&3=http%3A%2F%2FwwwWEBSITEcom%2Fcampaign.php%3Fcmd%3Dcreate%26mode%3Dppc&4=Vist&zone=header&mode=PPI&clicks=0&5=1&keywords=KEYWORD1%2C+was%2C+KEYWORD2%2C+KETWORD3%2C+KEYWORD4&dotw[1]=1&dotw[2]=1&dotw[3]=1&dotw[4]=1&dotw[5]=1&dotw[6]=1&dotw[0]=1
You change AND ads_id= to AND id= because that is the field name in the SQL statement, and seemingly the field name has changed.
You do not change $ads_id because that is the name of your PHP variable, and this works fine as it is and does not need to be the same as the field name.
On a wider level, you should sit and figure out how the last line of the PHP quoted puts together the SQL statement quoted in the error. You should know that the . is used to concatenate strings together, that PHP strings must start and end with the same character but that can be either ' or ", and that the SQL statement requires ' around values.
Also, if you've updated a third-party software script and it's now incompatible with your database you should look to see if there was some sort of data migration script that you've not run.
Depends. Is the id column containing the same information as ads_id? If so, yes you should change it. If no, you should figure out what happened to the ids and why they were removed.

Laravel 4 query builder - not null column not found

Route::get('/test', function(){
return DB::table('table')->where_not_null('column')->get();
});
In Laravel 4 I have the following route, obviously with table and column replaced. I had it in the controller but it wasn't working, so I moved it to a test route.
The error I am getting is:
SQLSTATE[42S22]: Column not found: 1054 Unknown column '_not_null' in 'where clause' (SQL: select * from `table` where `_not_null` = column)
https://tower.la.utexas.edu/docs/database/fluent#where
Documentation says:
return DB::table('table')->where_null('column')->get();
It should be
return DB::table('table')->whereNull('column')->get();
Or
return DB::table('table')->whereNotNull('column')->get();
You have used where_not_null.This is the right reference.
See the proper writing for that: http://laravel.com/docs/queries#selects
DB::table('table')->whereNotNull('column')->get();
The documentation states that following the table declaration you should put the query builder information, where_null, where_not_null, where_in.
However that doesn't work. I'm not sure why, it makes no sense, and is frustrating. However, this does work.
return DB::table('user')->whereuserName('not_null')->get();
By placing the column name where the documentation says to put the query, and the query where the documentation says to put the column you are able to execute your query. To note, camel case is converted to snake case in the query, so the column has to be named user_name.
I am posting this because I attempted googling it and was not able to find anything.

PHP/PostgreSQL database writing issue

I'm having problems writing data from a form to multiple datatables on my PostgreSQL database.
Here is my data model
CREATE TABLE institutions(i_id PK, name text, memberofstaff REFERENCES staff u_id);
CREATE TABLE staff(u_id PK, username text, password text, institution REFERENCES institutions i_id);
So its a 1:1 relationship. These tables have been set up fine. It's the PHP script I'm having difficult with. I'm using CTE-datamodifying or at least trying to but I keep receiving errors on submit.
The PHP:
$conn = pg_connect('database information filled out in code');
$result = pg_query("WITH x AS (
INSERT INTO staff(username, password, institution)
VALUES('$username', '$password', nextval('institutions_i_id_seq'))
RETURNING u_id, i_id)
INSERT INTO institutions (i_id, name, memberofstaff)
SELECT x.i_id, x.u_id, '$institution'
FROM x");
pg_close($conn);
So that's the code and the error I get is:
Warning: pg_query() [function.pg-query]: Query failed: ERROR: relation "institutions_i_id_seq" does not exist LINE 3: VALUES('AberLibrary01', '', nextval('institutions_i_id_se... ^ in DIRECTORY LISTING(I replaced this) on line 22
Anyone got any ideas?
Did you actually create the table with the column types of institutions.i_id and staff.u_id set to serial? Or create the sequence manually?
If the former, you don't need to explicitly use nextval anyway. If the latter, double-check the sequence name.
This would ideally be a comment, but I think it might have something to do with:
$'password' which should be '$password' on the fourth line of that example.

trying to use SOUNDEX in query but getting an error in terms of database columns in mysql

Trying to figure out what went wrong, must be a silly syntax.
$objDatabase = QApplication::$Database[1];
$strQuery = 'UPDATE `account` SET `sndx`=SOUNDEX("'.$objAccount->Name.'") WHERE `Id`='.$aid;
$objDbResult = $objDatabase->Query($strQuery);
The error I get is:
MySqli Error: Unknown column 'sndx' in 'field list'
Exception Type: QMySqliDatabaseException
There is no sndx column. The intent is to match values in account using SOUNDEX....
Well, you've answered your own question. If there is no sndx column, you can't set a value to it which is why the query fails.
Update your table to have an sndx column.

Categories