Solved

SQL Column not found

Posted on 2016-09-05
7
45 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 31

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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 31

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 31

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

920 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