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
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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 ;

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.