Jump to content

Syntax Error


anevins

Recommended Posts

I'll just post the query because I can't figure out the syntax error:

 

$query = "INSERT INTO report, location, person, stick (organisation, phoneNo, firstName, middleName, lastName, street, town, city, size, colour, make)

VALUES ('$organisation', '$phone', '$firstname', '$middlename', '$lastname', '$street', '$town', '$city','$size', '$colour', '$model')

WHERE report.sightingStick = stick.sid AND report.reporter = person.pid AND report.missingLocation = location.lid";

 

Any ideas?

Link to comment
Share on other sites

Okay I've separated them out since I couldn't join them up with WHERE...

Here's the new code:

 

	$query = "INSERT INTO stick (sid, size, colour, make) VALUES ('','$size', '$colour', '$model')";
	$query = "INSERT INTO report (rid, organisation, phoneNo) VALUES ('','$organisation', '$phone')
				SELECT sid FROM stick, report
				WHERE report.sightingStick = stick.sid";
	$query = "INSERT INTO person (pid, firstName, middleName, lastName) VALUES ('','$firstname', '$middlename', '$lastname') 
				SELECT reporter FROM report, person
				WHERE report.reporter = person.pid";
	$query = "INSERT INTO location(lid, street, town, city) VALUES ('', '$street', '$town', '$city')
				SELECT missingLocation FROM report, location
				WHERE report.missingLocation = location.lid";

Link to comment
Share on other sites

I originally wanted to INSERT data but I realised I needed the data which was inserted, to be relative to the table in its relationship.

 

What I think its supposed to do :

 

The SELECT grabs the two keys, one foreign and one primary which are ready for the WHERE statement.

 

 

Link to comment
Share on other sites

Here's the code again but with explanations of each SELECT statement

 

No SELECT:

		$query = "INSERT INTO stick (sid, size, colour, make) VALUES ('','$size', '$colour', '$model')";

 

Grab the foreign key of 'sightingStick' in table 'stick' and match it with the report:

		$query = "INSERT INTO report (rid, organisation, phoneNo) VALUES ('','$organisation', '$phone')
				SELECT sid,  sightingStick FROM stick, report
				WHERE report.sightingStick = stick.sid";

 

Grab the foreign key of 'reporter' in the table 'report' and match it with that person

$query = "INSERT INTO person (pid, firstName, middleName, lastName) VALUES ('','$firstname', '$middlename', '$lastname') 
				SELECT pid, reporter FROM report, person
				WHERE report.reporter = person.pid";

 

Grab for foreign key of 'missingLocation' in the table 'location' and match it with that report

		$query = "INSERT INTO location(lid, street, town, city) VALUES ('', '$street', '$town', '$city')
				SELECT lid, missingLocation FROM report, location
				WHERE report.missingLocation = location.lid";

Link to comment
Share on other sites

 

== Table structure for table stick

 

|------

|Field|Type|Null|Default

|------

|//**sid**//|int(11)|No|

|type|enum('MB', 'GB')|No|

|size|int(3)|No|

|colour|varchar(20)|No|

|make|char(220)|No|

|missingLocation|int(11)|Yes|NULL

|belongs|int(11)|Yes|NULL

 

== Table structure for table report

 

|------

|Field|Type|Null|Default

|------

|//**rid**//|int(11)|No|

|organisation|char(220)|No|

|rfc_date|date|No|

|phoneNo|varchar(18)|No|

|sightingStick|int(11)|Yes|NULL

|Reporter|int(11)|Yes|NULL

 

== Table structure for table location

 

|------

|Field|Type|Null|Default

|------

|//**lid**//|int(11)|No|

|street|char(220)|No|

|town|varchar(20)|No|

|city|varchar(20)|No|

 

== Table structure for table person

 

|------

|Field|Type|Null|Default

|------

|//**pid**//|int(11)|No|

|firstName|char(220)|No|

|middleName|char(220)|No|

|lastName|char(220)|No|

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.