Solved

SQL Column not found

Posted on 2016-09-05
7
42 Views
Last Modified: 2016-09-05
Hello,

If I put this in my navicat app as a query it inserts it into the table, if I try to do it via php it says that the column can not be found. Any clue as to why?

Works in Navicat
INSERT INTO properties (
	ListingType,
	ListingStatus,
	StreetAddress,
	UnitNumber,
	City,
	State,
	Zip,
	DisplayAddress,
	Price,
	MlsId,
	VirtualTourUrl,
	ShortSale,
	BankOwned,
	Availability,
	LeaseTerm,
	DepositFees,
	UtilitiesIncluded,
	PetsAllowed,
	Title,
	PropertyType,
	Bedrooms,
	Bathrooms,
	LivingArea,
	LotSize,
	YearBuilt,
	Description,
	user_id,
	PropertyImages
)
VALUES
	(
		'2',
		'1',
		'4857 E Lafayette Blvd',
		'',
		'Phoenix',
		'AZ',
		'85018',
		'1',
		'343',
		'',
		'',
		'1',
		'1',
		'',
		'',
		'',
		'',
		'',
		'',
		'Townhouse',
		'1',
		'2.5',
		'2953',
		'23954',
		'1964',
		'',
		'1',
		''
	)

Open in new window


Doesn't work in PHP (  Unknown column 'ListingType' in 'field list' )
$insert_query = mysqli_query($conn,"INSERT INTO properties (
	ListingType,
	ListingStatus,
	StreetAddress,
	UnitNumber,
	City,
	State,
	Zip,
	DisplayAddress,
	Price,
	MlsId,
	VirtualTourUrl,
	ShortSale,
	BankOwned,
	Availability,
	LeaseTerm,
	DepositFees,
	UtilitiesIncluded,
	PetsAllowed,
	Title,
	PropertyType,
	Bedrooms,
	Bathrooms,
	LivingArea,
	LotSize,
	YearBuilt,
	Description,
	user_id,
	PropertyImages
)
VALUES
	(
		'2',
		'1',
		'4857 E Lafayette Blvd',
		'',
		'Phoenix',
		'AZ',
		'85018',
		'1',
		'343',
		'',
		'',
		'1',
		'1',
		'',
		'',
		'',
		'',
		'',
		'',
		'Townhouse',
		'1',
		'2.5',
		'2953',
		'23954',
		'1964',
		'',
		'1',
		'')"); 

Open in new window

0
Comment
Question by:movieprodw
  • 4
  • 3
7 Comments
 
LVL 30

Expert Comment

by:Marco Gasi
ID: 41785158
Can you show the CREATE SQL code for that table?
Anyway, you could solve the issue just omitting to specify columns' names:
$insert_query = mysqli_query($conn,"INSERT INTO properties 
VALUES
	(
		'2',
		'1',
		'4857 E Lafayette Blvd',
		'',
		'Phoenix',
		'AZ',
		'85018',
		'1',
		'343',
		'',
		'',
		'1',
		'1',
		'',
		'',
		'',
		'',
		'',
		'',
		'Townhouse',
		'1',
		'2.5',
		'2953',
		'23954',
		'1964',
		'',
		'1',
		'')"); 

Open in new window

0
 
LVL 1

Author Comment

by:movieprodw
ID: 41785166
Please see attached.

Actual query in myphp
INSERT INTO properties ( ListingType, ListingStatus, StreetAddress, UnitNumber, City, State, Zip, DisplayAddress, Price, MlsId, VirtualTourUrl, ShortSale, BankOwned, Availability, LeaseTerm, DepositFees, UtilitiesIncluded, PetsAllowed, Title, PropertyType, Bedrooms, Bathrooms, LivingArea, LotSize, YearBuilt, Description, user_id, PropertyImages) VALUES ('2','1','4857 E Lafayette Blvd','','Phoenix','AZ','85018','1','343','','','1','1','','','','','','','Townhouse','1','2.5','2953','23954','1964','','1','')

Open in new window


Actual PHP query copied from above and ran, does not work.
$insert_query = mysqli_query($conn,"INSERT INTO properties ( ListingType, ListingStatus, StreetAddress, UnitNumber, City, State, Zip, DisplayAddress, Price, MlsId, VirtualTourUrl, ShortSale, BankOwned, Availability, LeaseTerm, DepositFees, UtilitiesIncluded, PetsAllowed, Title, PropertyType, Bedrooms, Bathrooms, LivingArea, LotSize, YearBuilt, Description, user_id, PropertyImages) VALUES ('2','1','4857 E Lafayette Blvd','','Phoenix','AZ','85018','1','343','','','1','1','','','','','','','Townhouse','1','2.5','2953','23954','1964','','1','')"); 

Open in new window

0
 
LVL 1

Author Comment

by:movieprodw
ID: 41785168
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 30

Expert Comment

by:Marco Gasi
ID: 41785175
Have you tried to omit column names as I suggested in my comment?
0
 
LVL 1

Author Comment

by:movieprodw
ID: 41785177
Yes
' Column count doesn't match value count at row 1'
0
 
LVL 30

Accepted Solution

by:
Marco Gasi earned 500 total points
ID: 41785191
Ah ok, you're not inserting a value for each column... A last idea: you can wrap each colimn name in `:
$insert_query = mysqli_query($conn,"INSERT INTO properties (
	`ListingType`,
	`ListingStatus`,
	`StreetAddress`,
	`UnitNumber`,
	`City`,
	`State`,
	`Zip`,
	`DisplayAddress`,
	`Price`,
	`MlsId`,
	`VirtualTourUrl`,
	`ShortSale`,
	`BankOwned`,
	`Availability`,
	`LeaseTerm`,
	`DepositFees`,
	`UtilitiesIncluded`,
	`PetsAllowed`,
	`Title`,
	`PropertyType`,
	`Bedrooms`,
	`Bathrooms`,
	`LivingArea`,
	`LotSize`,
	`YearBuilt`,
	`Description`,
	`user_id`,
	`PropertyImages`
)
VALUES
	(
		'2',
		'1',
		'4857 E Lafayette Blvd',
		'',
		'Phoenix',
		'AZ',
		'85018',
		'1',
		'343',
		'',
		'',
		'1',
		'1',
		'',
		'',
		'',
		'',
		'',
		'',
		'Townhouse',
		'1',
		'2.5',
		'2953',
		'23954',
		'1964',
		'',
		'1',
		'')"); 

Open in new window

0
 
LVL 1

Author Closing Comment

by:movieprodw
ID: 41785247
Thanks for working through it, it ended up a connection error, it is super strange that was the error it was giving.

Thank you so much for helping!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Creating and Managing Databases with phpMyAdmin in cPanel.
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now