techker Posted April 6, 2010 Share Posted April 6, 2010 hey guys i have tryed it all and i cant get it to work? mysql_connect("localhost", "me", "techker") or die(mysql_error()) ; mysql_select_db("a_me") or die(mysql_error()) ; $Make=$_POST['Make']; $Model=$_POST['Model']; $Year=$_POST['Year']; $Transmission=$_POST['Transmission']; $Full=$_POST['Full']; $Kill=$_POST['Kill']; $Color=$_POST['Color']; $Doors=$_POST['Doors']; $Description_short=$_POST['Description_short']; $Description_long=$_POST['Description_long']; $Location=$_POST['Location']; $Status=$_POST['Status']; $Retail_price=$_POST['Retail_price']; $Nego_price=$_POST['Nego_price']; $Cost_price=$_POST['Cost_price']; $Body=$_POST['Body']; $Image_2=$_POST['Image_2']; $Image_3=$_POST['Image_3']; $Image_4=$_POST['Image_4']; $Image_main=$_POST['Image_main']; $date = date("Y-m-d"); $ID=$_POST['ID']; $query = "UPDATE cars SET Make ='$Make', Model ='$Model',Year ='$Year', Transmission ='$Transmission',Full='$Full' , Kill ='$Kill',Color ='$Color', Doors ='$Doors', Description_short='$Description_short',Description_long ='$Description_long', Location ='$Location', Status ='$Status', Retail_price ='$Retail_price', Nego_Price ='$Nego_price', Cost_price ='$Cost_price', Body ='$Body' WHERE ID = '$ID' "; $result = mysql_query($query); Quote Link to comment https://forums.phpfreaks.com/topic/197761-update-query-not-working/ Share on other sites More sharing options...
Chris92 Posted April 6, 2010 Share Posted April 6, 2010 Try see if there's an error in your SQL syntax $result = mysql_query($query) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/197761-update-query-not-working/#findComment-1037821 Share on other sites More sharing options...
Pikachu2000 Posted April 6, 2010 Share Posted April 6, 2010 What error are you getting? $result = mysql_query($query) or die(mysql_error()); Also note that form data should NEVER be allowed in a DB query without being properly sanitized with typecasting, trim()ing, mysql_real_escape_string() etc. Quote Link to comment https://forums.phpfreaks.com/topic/197761-update-query-not-working/#findComment-1037826 Share on other sites More sharing options...
techker Posted April 6, 2010 Author Share Posted April 6, 2010 ya i forgot the die.. 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 'Kill ='123456',Color ='', Doors ='2', Description_short='',Description_long ='',' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/197761-update-query-not-working/#findComment-1037830 Share on other sites More sharing options...
Chris92 Posted April 6, 2010 Share Posted April 6, 2010 Then you might want to check in your table to see if those fields exist or are spelled properly or have the right type. Quote Link to comment https://forums.phpfreaks.com/topic/197761-update-query-not-working/#findComment-1037833 Share on other sites More sharing options...
techker Posted April 6, 2010 Author Share Posted April 6, 2010 table CREATE TABLE IF NOT EXISTS `cars` ( `ID` int(11) NOT NULL auto_increment, `Make` varchar(20) NOT NULL, `Model` varchar(20) NOT NULL, `Year` varchar(12) NOT NULL, `Transmission` varchar(20) NOT NULL, `Full` varchar(20) NOT NULL, `Kill` varchar(20) NOT NULL, `Color` varchar(20) NOT NULL, `Doors` varchar(20) NOT NULL, `Description_short` text NOT NULL, `Description_long` text NOT NULL, `Location` varchar(20) NOT NULL, `Status` varchar(20) NOT NULL, `Retail_price` varchar(20) NOT NULL, `Nego_Price` varchar(20) NOT NULL, `Cost_price` varchar(20) NOT NULL, `Image_main` varchar(50) NOT NULL, `Image_2` varchar(50) NOT NULL, `Image_3` varchar(50) NOT NULL, `Image_4` varchar(50) NOT NULL, `Date` date NOT NULL, `Body` varchar(25) NOT NULL, `Viewedcount` varchar(15) NOT NULL default '1', `Vin` varchar(25) NOT NULL, PRIMARY KEY (`ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=40 ; Quote Link to comment https://forums.phpfreaks.com/topic/197761-update-query-not-working/#findComment-1037842 Share on other sites More sharing options...
Chris92 Posted April 6, 2010 Share Posted April 6, 2010 Hrm, had a quick skim thorugh, can't be bothered looking much but it looks to be fine. I was thinking maybe you're trying to post something with a quotation mark or reserved SQL character, put this loop at the top to make sure everything will work alright: foreach( $_POST as $key => $value ) { $_POST[$key] = addslashes(htmlentities($value)); } If it still doesn't work it might be that you have an older version of mysql that requiers you use proper quotations in you syntax, eg: mysql_query("UPDATE `table` SET `field` = '$value'"); rather than mysql_qeury("UPDATE table SET filed = '$value'"); I'm not a real expert in SQL Quote Link to comment https://forums.phpfreaks.com/topic/197761-update-query-not-working/#findComment-1037847 Share on other sites More sharing options...
PFMaBiSmAd Posted April 6, 2010 Share Posted April 6, 2010 KILL is a reserved mysql keyword (there's a table in the documentation.) Either rename that column or enclose the name in back-ticks `` every time you put it into a query. Quote Link to comment https://forums.phpfreaks.com/topic/197761-update-query-not-working/#findComment-1037853 Share on other sites More sharing options...
techker Posted April 6, 2010 Author Share Posted April 6, 2010 hmm cant rename cause my insert is there to..so i quoted ` `Kill` it worked.but the query did not work..so im guessing that i have to `` all ?? Quote Link to comment https://forums.phpfreaks.com/topic/197761-update-query-not-working/#findComment-1037855 Share on other sites More sharing options...
PFMaBiSmAd Posted April 6, 2010 Share Posted April 6, 2010 Does the or die(mysql_error()) on the mysql_query() produce any message? Quote Link to comment https://forums.phpfreaks.com/topic/197761-update-query-not-working/#findComment-1037856 Share on other sites More sharing options...
techker Posted April 6, 2010 Author Share Posted April 6, 2010 no ... Quote Link to comment https://forums.phpfreaks.com/topic/197761-update-query-not-working/#findComment-1037857 Share on other sites More sharing options...
PFMaBiSmAd Posted April 6, 2010 Share Posted April 6, 2010 That would indicate that the WHERE clause does not match any row in your table. echo $query to see exactly what it contains and check to make sure that the value in $ID actually exists in your table. Quote Link to comment https://forums.phpfreaks.com/topic/197761-update-query-not-working/#findComment-1037859 Share on other sites More sharing options...
Pikachu2000 Posted April 6, 2010 Share Posted April 6, 2010 Are you sure the query failed? I created your table locally, and ran the query, both with all fields in backticks, and with only `Kill` in backticks, and it executed successfully both times. Quote Link to comment https://forums.phpfreaks.com/topic/197761-update-query-not-working/#findComment-1037862 Share on other sites More sharing options...
Pikachu2000 Posted April 6, 2010 Share Posted April 6, 2010 Of course, what PFMaBiSmAd just posted is also possible. Additionally, if you execute an identical UPDATE query multiple times, it will return "0 row(s) affected", because no fields were changed after the first UPDATE, even though the subsequent queries succeeded. Quote Link to comment https://forums.phpfreaks.com/topic/197761-update-query-not-working/#findComment-1037866 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.