Weird issue with PHP script not updating db

I have a fairly straightforward PHP script which grabs values from a preceding form and updates the specified record in a mySQL db.

Only problem is that although it appears to work (in that it goes through to the confirmation page) the values don’t get updated.

It doesn’t throw a syntax error so I guess it just isn’t seeing the condition in the WHERE clause- but don’t see how.

This is the code:


<?php

include ('../inc/dbconnect.php');

if($_POST['stocklist_updatetable'])
{
  // Grab the data from the first Stock List update form and assign to variables
  
  $carid = $_POST['_CarID'];
  
  $title1 =@$_POST['_IsLive'];
  $title2 =@$_POST['_IsArchived'];
  $title3 =@$_POST['_IsSold'];
  $title4 =@$_POST['_Title'];
  $title5 =@$_POST['_Variant'];
  $title6 =@$_POST['_Price'];
  $title7 =@$_POST['_Make'];
  $title8 =@$_POST['_BodyType'];
  $title9 =@$_POST['_ModelType'];
  $title10 =@$_POST['_ChassisNumber'];
  $title11 =@$_POST['_EngineNumber'];
  $title12 =@$_POST['_RegNumber'];
  $title13 =@$_POST['_DateFirstReg'];
  $title14 =@$_POST['_YearOfCar'];
  $title15 =@$_POST['_ExteriorColour'];
  $title16 =@$_POST['_InteriorColour'];
  $title17 =@$_POST['_Hood'];
  $title18 =@$_POST['_Odometer'];
  $title19 =@$_POST['_Steering'];
  $title20 =@$_POST['_Transmission'];
  $title21 =@$_POST['_FourWheelDrive'];
  $title22 =@$_POST['_NumberOfDoors'];
  $title23 =@$_POST['_EngineSize'];
  $title24 =@$_POST['_FuelType'];
  $title25 =@$_POST['_PreviousOwners'];
  $title26 =@$_POST['_Options'];
  $title27 =@$_POST['_Description'];
  
  $title28 =@$_POST['_Pic1'];
  $title29 =@$_POST['_Pic2'];
  $title30 =@$_POST['_Pic3'];
  $title31 =@$_POST['_Pic4'];
  $title32 =@$_POST['_Pic5'];
  $title33 =@$_POST['_Pic6'];
  $title34 =@$_POST['_Pic7'];
  $title35 =@$_POST['_Pic8'];
  $title36 =@$_POST['_Pic9'];
  $title37 =@$_POST['_Pic10'];
  $title38 =@$_POST['_Pic11'];
  $title39 =@$_POST['_Pic12'];
  $title40 =@$_POST['_Pic13'];
  $title41 =@$_POST['_Pic14'];
  $title42 =@$_POST['_Pic15'];
  $title43 =@$_POST['_Pic16'];
  $title44 =@$_POST['_Pic17'];
  $title45 =@$_POST['_Pic18'];
  $title46 =@$_POST['_Pic19'];
  $title47 =@$_POST['_Pic20'];
  
  $trimmed1 = trim($title1); //trim whitespace from the stored variable
  $trimmed2 = trim($title2);
  $trimmed3 = trim($title3);
  $trimmed4 = trim($title4);
  $trimmed5 = trim($title5);
  $trimmed6 = trim($title6);
  $trimmed7 = trim($title7);
  $trimmed8 = trim($title8);
  $trimmed9 = trim($title9);
  $trimmed10 = trim($title10);
  $trimmed11 = trim($title11);
  $trimmed12 = trim($title12);
  $trimmed13 = trim($title13);
  $trimmed14 = trim($title14);
  $trimmed15 = trim($title15);
  $trimmed16 = trim($title16);
  $trimmed17 = trim($title17);
  $trimmed18 = trim($title18);
  $trimmed19 = trim($title19);
  $trimmed20 = trim($title20);
  $trimmed21 = trim($title21);
  $trimmed22 = trim($title22);
  $trimmed23 = trim($title23);
  $trimmed24 = trim($title24);
  $trimmed25 = trim($title25);
  $trimmed26 = trim($title26);
  $trimmed27 = trim($title27);
  $trimmed28 = trim($title28);
  $trimmed29 = trim($title29);
  $trimmed30 = trim($title30);
  $trimmed31 = trim($title31);
  $trimmed32 = trim($title32);
  $trimmed33 = trim($title33);
  $trimmed34 = trim($title34);
  $trimmed35 = trim($title35);
  $trimmed36 = trim($title36);
  $trimmed37 = trim($title37);
  $trimmed38 = trim($title38);
  $trimmed39 = trim($title39);
  $trimmed40 = trim($title40);
  $trimmed41 = trim($title41);
  $trimmed42 = trim($title42);
  $trimmed43 = trim($title43);
  $trimmed44 = trim($title44);
  $trimmed45 = trim($title45);
  $trimmed46 = trim($title46);
  $trimmed47 = trim($title47);
  
  $apostrophefix_description = str_replace("'", "&#039;", $trimmed27); 


// Build SQL Query  
$query = "UPDATE cars SET is_live = '$trimmed1', is_archived = '$trimmed2', Sold = '$trimmed3', title = '$trimmed4', Variant = '$trimmed5', Price = '$trimmed6', Make = '$trimmed7', Body_type = '$trimmed8', Model_type = '$trimmed9', Chassis_no = '$trimmed10', Engine_no = '$trimmed11', Full_registration = '$trimmed12', First_registration = '$trimmed13', Year_of_car = '$trimmed14', Colour = '$trimmed15', Interior = '$trimmed16', Hood = '$trimmed17', Mileage = '$trimmed18', Steering = '$trimmed19', Transmission = '$trimmed20', Four_wheel_drive = '$trimmed21', Doors = '$trimmed22', Engine_size = '$trimmed23', Fuel_type = '$trimmed24', Previous_owners = '$trimmed25', Options = '$trimmed26', car_description = '$apostrophefix_description', pic1 = '$trimmed28', pic2 = '$trimmed29', pic3 = '$trimmed30', pic4 = '$trimmed31', pic5 = '$trimmed32', pic6 = '$trimmed33', pic7 = '$trimmed34', pic8 = '$trimmed35', pic9 = '$trimmed36', pic10 = '$trimmed37', pic11 = '$trimmed38', pic12 = '$trimmed39', pic13 = '$trimmed40', pic14 = '$trimmed41', pic15 = '$trimmed42', pic16 = '$trimmed43', pic17 = '$trimmed44', pic18 = '$trimmed45', pic19 = '$trimmed46', pic20 = '$trimmed47' WHERE carid = '$carid'"; // specify the table and field names for the SQL query
}
if($result = mysql_query($query)) 
{ 
//go to the new member confirmation page
		header('location: updateconfirmed.php');
		exit;
} 
else 
{ 
echo "ERROR: ".mysql_error(); 
}

?>

Anyone got any ideas?

Print out $carid variable as well as $query.
And see if it all right.

And your code really need some rewrite, to eliminate these monuments of assignments.

Seems to be working now, I edited the pulling of carid on the previous page so it was getting the value correctly.

Unfortunately there are lots of different fields with different data in the table to be filled in during the edit so the script is long accordingly.

Unfortunately you are not so good with programming :slight_smile:
The programming goal itself is to eliminate such long lists.
At least you can make it 2 times shorter by doing trim at once
$title1 =trim($_POST[‘_IsLive’]);

and whole list can be eliminated too, as well as manual query building.

field names can be easily fetched from the database…

The use of the error suppression operator @ is not a good idea as it hides errors that you may need to improve or fix code with, for a live site you should disbaled error display with:

ini_set('display_errors', 0);