jesushax Posted July 9, 2009 Share Posted July 9, 2009 heres the code $posts = $_POST; unset($posts['ID']); $SQL = "UPDATE cwi_computers SET"; foreach($posts as $key => $value){ $SQL .= " `$key`='$value',"; } $SQL .= rtrim($SQL,","); $SQL .= " WHERE ID='".$_POST["ID"]."'"; echo "<p>".$SQL."</p>"; mysql_query($SQL) or die(mysql_error()); Heres the Output UPDATE cwi_computers SET `ComputerID`='CWR001', `Location`='On & Off All Sites', `ComputerName`='Alex-Laptop', `CurrentIP`='192.168.10.19', `CurrentUser`='Steve Craker', `OperatingSystem`='Windows Vista Business', `Motherboard`='', `Motherboard_URL`='', `CPU`='Inter Centrino Core 2', `CPU_Speed`='2.26', `Core`='x2', `RAM`='3GB', `RAM_URL`='', `HDD`='320GB', `OpticalDrives`='DVD-RW',UPDATE cwi_computers SET `ComputerID`='CWR001', `Location`='On & Off All Sites', `ComputerName`='Alex-Laptop', `CurrentIP`='192.168.10.19', `CurrentUser`='Steve Craker', `OperatingSystem`='Windows Vista Business', `Motherboard`='', `Motherboard_URL`='', `CPU`='Inter Centrino Core 2', `CPU_Speed`='2.26', `Core`='x2', `RAM`='3GB', `RAM_URL`='', `HDD`='320GB', `OpticalDrives`='DVD-RW' WHERE ID='1' 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 'UPDATE cwi_computers SET `ComputerID`='CWR001', `Location`='On & Off All Sites',' at line 1 ive just noticed that the echo of the statement shows that its posting the results twice anyone know why? Cheers Quote Link to comment https://forums.phpfreaks.com/topic/165348-solved-sql-error-i-cant-find-it-can-someone-with-fresh-eyes-help-me-out/ Share on other sites More sharing options...
jesushax Posted July 9, 2009 Author Share Posted July 9, 2009 found it was the . on rtrim Quote Link to comment https://forums.phpfreaks.com/topic/165348-solved-sql-error-i-cant-find-it-can-someone-with-fresh-eyes-help-me-out/#findComment-871996 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.