一列未在表中更新

时间:2018-04-09 19:11:23

标签: php mysql

我正在尝试更新数据库中的表。它通过HogId编号查找一行,并更新该行。所有列都将更新,但PetName列。我检查并设置了变量,HogId是正确的,所有列都与表匹配。我错过了什么?我还没有完成,因为我还没有完成一些安全措施。

<?php
session_start();
require_once('../mysqlconnect.php');

//ini_set('display_errors', 1);
//ini_set('display_startup_errors', 1);
//error_reporting(E_ALL);
?>

<?php

if(isset($_SESSION['HHAdminUserId'])&&isset($_SESSION['HHAdminName'])){     

    mysqli_query($link, "SET AUTOCOMMIT = 0");
        $PetName = $_POST['PetName'];
        $BirthDate = $_POST['BirthDate'];
        $Descriptors = $_POST['Descriptors'];
        $Sex = $_POST['Sex'];
        $Breeder = $_POST['Breeder'];
        $OwnedBy = $_POST['Owner'];
        $HogId = $_POST['HogId'];

        //All areas that need updated when HogId for a hedgehog changes
        if(isset($_POST['changeBreeder'])){
            $HogIdEx = explode("-",$HogId);
            $HogIdOld = $HogIdEx[0];
            $UpdatedHogId = $Breeder."-".$HogIdEx[1];

                $UpdateBasic = "UPDATE HedgehogBasic set HogId = '$UpdatedHogId' WHERE HogId = '$HogId' limit 1";
                $execUpdateBasic = @mysqli_query($link, $UpdateBasic);
                    if(!$execUpdateBasic){
                        rollback_die("The inquiry could not be completed because : ");
                            }else{
                                echo "Change in 'HedgehogBasic' table Successful!<br />";
                            }

                $UpdateTransfer = "UPDATE Transfer set HogId = '$UpdatedHogId' WHERE HogId = '$HogId'";
                $execUpdateTransfer = @mysqli_query($link, $UpdateTransfer);
                    if(!$execUpdateTransfer){
                        rollback_die("The inquiry could not be completed because : ");
                            }else{
                                echo "Change in 'Transfer' table Successful!<br />";
                            }
                $UpdateUnknownLine = "UPDATE UnknownLine set HogId = '$UpdatedHogId' WHERE HogId = '$HogId'";
                $execUpdateUnknownLine = @mysqli_query($link, $UpdateUnknownLine);
                    if(!$execUpdateUnknownLine){
                        rollback_die("The inquiry could not be completed because : ");
                            }else{
                                echo "Change in 'UnknownLine' table Successful!<br />";
                            }

                $UpdatePhotos = "UPDATE Photos set HogId = '$UpdatedHogId' WHERE HogId = '$HogId'";
                $execUpdatePhotos = @mysqli_query($link, $UpdatePhotos);
                    if(!$execUpdatePhotos){
                        rollback_die("The inquiry could not be completed because : ");
                            }else{
                                echo "Change in 'Photos' table for HogId Successful!<br />";
                            }

                function UpdateBreeding($BreedingCol, $UpdatedHogId, $HogId){
                global $link;
                $UpdateBreeding = "UPDATE Breeding SET $BreedingCol = '$UpdatedHogId' WHERE $BreedingCol = '$HogId'";
                $execUpdateBreeding = @mysqli_query($link, $UpdateBreeding);
                    if(!$execUpdateBreeding){
                        rollback_die("The inquiry could not be completed because : ");
                            }else{
                                echo "Change in 'Breeding' table for $BreedingCol Successful!<br />";
                            }
                }

                UpdateBreeding ('HogletHogId', $UpdatedHogId, $HogId);
                UpdateBreeding ('BoarHogId', $UpdatedHogId, $HogId);
                UpdateBreeding ('SowHogId', $UpdatedHogId, $HogId);


                $UpdatePhotosImg = "SELECT Link FROM Photos WHERE HogId = '$UpdatedHogId' ";
                $execUpdatePhotosImg = @mysqli_query($link, $UpdatePhotosImg);
                    if(!$execUpdatePhotosImg){
                        rollback_die("The inquiry could not be completed because : ");
                            }else{
                                while($one_row = mysqli_fetch_assoc($execUpdatePhotosImg)){
                                    $Link = $one_row['Link'];
                                    $UpdatedLink = str_replace("$HogIdOld","$Breeder","$Link");

                                $UpdatePhotosLink = "UPDATE Photos set Link = '$UpdatedLink' WHERE HogId = '$UpdatedHogId'";
                                $execUpdatePhotosLink = @mysqli_query($link, $UpdatePhotosLink);
                                    if(!$execUpdatePhotosLink){
                                        rollback_die("The inquiry could not be completed because : ");
                                            }else{
                                                echo "Change in 'Photos' table for Link Successful!<br />";
                                            }   
                                }
                            }

            $HogId = $UpdatedHogId;
            }

        $Update = "UPDATE HedgehogBasic SET BirthDate ='$BirthDate', Descriptors = '$Descriptors', Sex = '$Sex', Breeder = '$Breeder', OwnedBy = '$OwnedBy', PetName = '$PetName' WHERE HogId = '$HogId' Limit 1";
        $execUpdate = @mysqli_query($link, $Update);

    if(!$execUpdate){
        rollback_die("The inquiry could not be completed because : ");
            }else{
                echo "Update Successful!<br />";
            }

0 个答案:

没有答案