SitePoint Sponsor |
|
User Tag List
Results 1 to 18 of 18
-
Aug 17, 2007, 11:17 #1
- Join Date
- Apr 2007
- Posts
- 690
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
What is wrong with this mysql statement?
What is wrong with this mysql statement?
PHP Code:UPDATE timesheet
SET
monlaborcode0 = '$_POST['monlaborcode0']',
monexchange0 = '$_POST['monexchange0']',
monworkjob0 = '$_POST['monworkjob0']',
monreghours0 = '$_POST['monreghours0']',
WHERE username = '$_SESSION[user_name]'")
-
Aug 17, 2007, 11:18 #2
- Join Date
- Feb 2003
- Location
- Slave I
- Posts
- 23,424
- Mentioned
- 2 Post(s)
- Tagged
- 1 Thread(s)
What does Mysql say? It will give you an error message letting you know the error is.
Also, you may have syntax errors there with your quotes. You should clearly separate your PHP from your SQL.
-
Aug 17, 2007, 11:23 #3
- Join Date
- Apr 2007
- Posts
- 690
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The server I use has error reporting off. So I'm not sure. It may be the quotes idk.
-
Aug 17, 2007, 11:30 #4
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
dangling comma
see also these previous threads for examples of how using the leading comma convention would've avoided it
http://www.sitepoint.com/forums/showthread.php?t=332060
http://www.sitepoint.com/forums/showthread.php?t=311102
http://www.sitepoint.com/forums/showthread.php?t=307641
http://www.sitepoint.com/forums/showthread.php?t=237924
http://www.sitepoint.com/forums/showthread.php?t=184470
-
Aug 17, 2007, 11:37 #5
- Join Date
- Apr 2007
- Posts
- 690
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You suggest:
PHP Code:UPDATE timesheet
SET monlaborcode0 = '$_POST['monlaborcode0']'
, monexchange0 = '$_POST['monexchange0']'
, monworkjob0 = '$_POST['monworkjob0']'
, monreghours0 = '$_POST['monreghours0']'
WHERE username = '$_SESSION[user_name]'")
-
Aug 17, 2007, 11:49 #6
-
Aug 17, 2007, 11:54 #7
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
-
Aug 17, 2007, 11:57 #8
- Join Date
- Apr 2007
- Posts
- 690
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Those quotes have been removed, still facing the error.
-
Aug 17, 2007, 12:03 #9
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
sounds like it's not a mysql problem, moving thread to php forum
-
Aug 17, 2007, 12:16 #10
you have to enclose the string with double quotes:
PHP Code:UPDATE timesheet
SET
monlaborcode0 = '".$_POST['monlaborcode0']."',
monexchange0 = '".$_POST['monexchange0']."',
monworkjob0 = '".$_POST['monworkjob0']."',
monreghours0 = '".$_POST['monreghours0']."',
WHERE username = '".$_SESSION[user_name]."'")
my mobile portal
ghiris.ro
-
Aug 17, 2007, 12:37 #11
- Join Date
- Apr 2007
- Posts
- 690
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
okay it's telling me this now:
PHP Code:INSERT Error: 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 'SET monlaborcode0 = 'asdf', monexchange0 = 'asdf', monworkjob0 =
-
Aug 17, 2007, 12:51 #12
sorry I didn't notice the comma
PHP Code:$x = mysql_query("UPDATE timesheet
SET
monlaborcode0 = '".$_POST['monlaborcode0']."',
monexchange0 = '".$_POST['monexchange0']."',
monworkjob0 = '".$_POST['monworkjob0']."',
monreghours0 = '".$_POST['monreghours0']."'
WHERE username = '".$_SESSION['user_name']."'") or die(mysql_error());
my mobile portal
ghiris.ro
-
Aug 17, 2007, 19:50 #13
Things are easier to debug when you have a clean separation between different layers.
PHP Code:$sql = <<<SQL
UPDATE timesheet
SET
monlaborcode0 = '%s'
, monexchange0 = '%s'
, monworkjob0 = '%s'
, monreghours0 = '%s'
WHERE
username = '%s'
SQL;
$sql = sprintf($sql,
$_POST['monlaborcode0'],
$_POST['monexchange0'],
$_POST['monworkjob0'],
$_POST['monreghours0'],
$_SESSION['user_name']
);
-
Aug 21, 2007, 13:47 #14
- Join Date
- Apr 2007
- Posts
- 690
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Here is the error code I'm getting:
PHP Code:INSERT Error: 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 'SET monlaborcode0 = '740' WHERE username = 'test')' at line 4
PHP Code:ON DUPLICATE KEY
UPDATE timesheet
SET
monlaborcode0 = '$monlaborcode0'
WHERE
username = '".$_SESSION['user_name']."')")
-
Aug 21, 2007, 14:09 #15
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
that's not how the ON DUPLICATE syntax works
you want something likeCode:ON DUPLICATE KEY UPDATE monlaborcode0 = '$monlaborcode0'
-
Aug 21, 2007, 15:09 #16
- Join Date
- Jul 2006
- Posts
- 83
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
kill the single quote within the array
PHP Code:UPDATE timesheet
SET
monlaborcode0 = '$_POST[monlaborcode0]',
monexchange0 = '$_POST[monexchange0]',
monworkjob0 = '$_POST[monworkjob0]',
monreghours0 = '$_POST[monreghours0]',
WHERE username = '$_SESSION[user_name]'")
-
Aug 21, 2007, 15:35 #17
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
grumps, i think he's doing an INSERT, not an UPDATE
wickedneat, could you give us some more info please?
-
Aug 22, 2007, 10:30 #18
- Join Date
- Apr 2007
- Posts
- 690
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Bookmarks