Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Sep 2009
    Posts
    165
    Thanks
    16
    Thanked 0 Times in 0 Posts

    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 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("'""'"$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?

  • #2
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    Firstly try and echo out the $query so that you can see what it is that is being run in the db. If you paste that here it may help solve it.
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #3
    Regular Coder
    Join Date
    Sep 2009
    Posts
    165
    Thanks
    16
    Thanked 0 Times in 0 Posts
    I included

    PHP Code:
    echo $query
    And got the following output:

    PHP Code:
    UPDATE cars SET is_live 'Y'is_archived 'N'Sold 'no'title 'Aston Martin V8 Zagato Volante'Variant 'Volante'Price '750000'Make 'Aston Martin'Body_type 'Convertable'Model_type 'V8 Zagato'Chassis_no 'SCFCV81Z3JTR 30020'Engine_no 'V/585/0020'Full_registration 'G839 WGU'First_registration '1st November 1989'Year_of_car '1989'Colour 'Silver Metallic'Interior 'Burgundy'Hood 'Black'Mileage '17,000'Steering 'Right'Transmission 'Manual'Four_wheel_drive 'no'Doors '2'Engine_size '5.3'Fuel_type 'Petrol'Previous_owners '3'Options 'Exterior colour: Star Silver Metallic (Code: 8886L). Hood: Black Mohair.Interior colour: Burgundy Leather. Headlining: Black Alcantara. Carpets:'car_description 'With values nearing £2,000,000 each, the nineteen Zagato bodied DB4 GT’s have already become amongst the most desirable and valuable cars ever built'pic1 ''pic2 'DSC01223-1152018587366004_orig.jpg'pic3 'Astons_DB_General_046-1152018668461758_orig.jpg'pic4 'Img1269-1152018856729998_orig.jpg'pic5 'Img1230-1152018728253169_orig.jpg'pic6 'Img1278-1152018990752525_orig.jpg'pic7 'Img1284-1152018994552771_orig.jpg'pic8 ''pic9 ''pic10 ''pic11 ''pic12 ''pic13 ''pic14 ''pic15 ''pic16 ''pic17 ''pic18 ''pic19 ''pic20 '' WHERE carid '' 
    It looks as if carid is showing as blank which explains why it's running the query but not updating anything.

    I also echoed the $carid variable but that didn't show up at all. However it shows up fine on the previous page (where I have a line that tell's people what carid is being edited)

  • #4
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    You need to pass on the carid from the last page. How exactly (if at all) are you doing this?
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • Users who have thanked JAY6390 for this post:

    galahad3 (01-15-2010)

  • #5
    Regular Coder
    Join Date
    Sep 2009
    Posts
    165
    Thanks
    16
    Thanked 0 Times in 0 Posts
    Thanks, I checked and saw it wasn't pulling via row["carid"] from the db on the previous page (for presentation), seems to be fine now.

    Thanks for the pointers.

  • #6
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    No problem. If you want another pointer, consider moving your data into arrays with keys rather than $title1 $title2 have $title[2] $title[2]. You could then trim all of them with just
    PHP Code:
    array_map('trim'$title); 
    instead of all those trims
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •