Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

SQL Column not found

Posted on 2016-09-05
7
50 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
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.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

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.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

839 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