Jump to content

update query not working?


techker

Recommended Posts

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);

Link to comment
https://forums.phpfreaks.com/topic/197761-update-query-not-working/
Share on other sites

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.

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 ;

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.