Link to home
Start Free TrialLog in
Avatar of movieprodw
movieprodw

asked on

SQL Column not found

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

Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

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

Avatar of movieprodw
movieprodw

ASKER

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

Have you tried to omit column names as I suggested in my comment?
Yes
' Column count doesn't match value count at row 1'
ASKER CERTIFIED SOLUTION
Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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!