DZone Forums
Go Back   DZone Forums > Community > Languages & Frameworks > PHP
Reload this Page Error in your SQL syntax
Notices
Reply
 
LinkBack Thread Tools Display Modes
  (#1 (permalink)) Old
Member
 
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Jul 2009
Default Error in your SQL syntax - 07-09-2009, 04:47 PM

I am following Lynda PHP training, and I have recieved an error in SQL syntax. Can somebody please can help me? I am new with it, so I am sorry if it is stupid question.

I have try this code on two different systems:
Windows XP, PHP 5.2.8, MySQL 5.1.30 - xampp
Windows Vista, PHP 5.2.1, MySQL 5.1.35 - Zend Server CE

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 ' )' at line 4

<?php require_once("includes/connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php
$menu_name = $_POST['menu_name'];
$position = $_POST['position'];
$visible = $_POST['visible'];
?>
<?php
$query = "INSERT INTO menu (
menu_name, position, visible
) VALUES (
'{$menu_name}', {$position}, {$visible}
)";
$result = mysql_query($query, $connection);
if ($result) {
// Success!
header("Location: content.php");
exit;
} else {
// Display error message.
echo "<p>Menu creation failed.</p>";
echo "<p>" . mysql_error() . "</p>";
}
?>
<?php mysql_close($connection); ?>

HOWEVER when I have change:
'{$menu_name}', {$position}, {$visible}
into
'$menu_name', '$position', '$visible'

It start working, but is not passing any information about position and visible on XP
Warning: Cannot modify header information - headers already sent by (output started at D:\xampp\htdocs\fixedgearleeds\includes\functions. php:98) in D:\xampp\htdocs\fixedgearleeds\create_subject.php on line 19
Plus I am recieving an error's on Vista where is still not working
Incorrect integer value: '' for column 'position' at row 1.

Thanks for any help!
Reply With Quote
  (#2 (permalink)) Old
Member
 
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
Join Date: Sep 2008
Default 07-11-2009, 05:22 PM

Start by removing any whitespace characters from the beginning and end of the functions.php file. There should be nothing before "<?php" and nothing after "?>".
Reply With Quote
  (#3 (permalink)) Old
Member
 
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Oct 2009
Default 10-27-2009, 08:48 PM

Just have 1 set of <?php's

PHP Code:
<?php
all your code in here
?>
Try this:

PHP Code:
$query "INSERT INTO menu (menu_name, position, visible) VALUES (
'{$menu_name}', '{$position}', '{$visible}')"

You need to keep the same formatting around the variables

'var1','var2','var3'

or

var1,var2,var3

(with or without quotes)


Abbie
webcam girls
Reply With Quote
Reply

Tags
insert, sql

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Invalid syntax error bhamilton Eclipse 0 06-12-2009 02:34 PM
code syntax highlighting in SWT markitus Java 0 12-03-2008 07:59 AM
E-mail syntax restriction too strict Trinition Feedback 0 08-15-2008 11:05 AM
Question/Problem w/ my Program....I'm I missing something here in my syntax?? thx Felipe M Java 1 03-04-2008 04:13 AM
Problems with WYSIWYG Editor and Code Syntax Highlighting walkere Zones 4 01-27-2008 05:59 PM


Copyright 1997-2009, DZone, Inc.
vBulletin Skin developed by: vBStyles.com