SQL syntax

You have an error in your SQL syntax;

Page 1 of 1

2 Replies - 1045 Views - Last Post: 21 April 2009 - 05:34 AM Rate Topic: -----

#1 rollerdead  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 02-November 08

SQL syntax

Post icon  Posted 20 April 2009 - 05:26 PM

hello guys, i was copy this source code from lynda.com essantial tutorial. i got this error and i didnt know where to fix it.

		if(empty($errors)){
			//Perform Update
		$id = mysql_prep($_GET['subj']);
		$menu_name = mysql_prep($_POST['menu_name']);
		$position = mysql_prep($_POST['position']);
		$visible = mysql_prep($_POST['position']);
		
//the error was started here
		$query = "UPDATE subjects SET
					menu_name = '{$menu_name}';
					position = {$position},
					visible = {$visible}
					WHERE id = {$id}";
			$result = mysql_query($query, $connection);


error message :
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'position = 1>, visible = 1> WHERE id = 1' at line 3

thanks

Is This A Good Question/Topic? 0
  • +

Replies To: SQL syntax

#2 BGDeveloper  Icon User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 84
  • Joined: 01-April 09

Re: SQL syntax

Posted 21 April 2009 - 12:24 AM

Well you are blind, xD
 menu_name = '{$menu_name}';

Was This Post Helpful? 0
  • +
  • -

#3 pemcconnell  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 54
  • View blog
  • Posts: 472
  • Joined: 05-August 08

Re: SQL syntax

Posted 21 April 2009 - 05:34 AM

just to give you a helping hand for debuging SQL in the future, you should append the following onto your mysql_query():

mysql_query($query, $connection)or die(mysql_error());



but thankfully the error in this case was descriptive enough. Looking at your code you have put a semi-colon after menu_name (as mentioned above) but also it looks like you are trying to pass 1> as an integer value into position and visible. This should either be a number (1) or a string if you need to store it as '1>'
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1