Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 63
  • Last Modified:

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

0
movieprodw
Asked:
movieprodw
  • 4
  • 3
1 Solution
 
Marco GasiFreelancerCommented:
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
 
movieprodwAuthor Commented:
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
 
movieprodwAuthor Commented:
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Marco GasiFreelancerCommented:
Have you tried to omit column names as I suggested in my comment?
0
 
movieprodwAuthor Commented:
Yes
' Column count doesn't match value count at row 1'
0
 
Marco GasiFreelancerCommented:
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
 
movieprodwAuthor Commented:
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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now