0

PHPを使用して操作するためのフロントエンドとともにMySQLデータベースを作成しました。ただし、手動でデータベースにコンテンツを追加することはできますが、フロントエンドを利用することはできません。フロントエンドのフォーム フィールドでデータを送信しようとすると、「候補者名が重複しています」というプロンプトが表示されます。

次の PHP ファイルは、フロントエンドを表示するための一般的なスクリプトです。

<?php   
    if(isset($_POST['sbmtbtn']) && ($_POST['sbmtbtn'] != ""))
    {

        $desc           =  strip_tags($_POST['txtdesc']);
        $date           =  glb_func_chkvl($_POST['txtdate']);
        $first           =  glb_func_chkvl($_POST['txtfirst']);
        $last            =  glb_func_chkvl($_POST['txtlast']);
        $skill           =  glb_func_chkvl($_POST['txtskill']);
        $sub1            =  glb_func_chkvl($_POST['txtsub1']);
        $sub2            =  glb_func_chkvl($_POST['txtsub2']);
        $person      =  glb_func_chkvl($_POST['txtperson']);
        $company         =  glb_func_chkvl($_POST['txtcompany']);
        $location        =  glb_func_chkvl($_POST['txtlocation']);
        $complex         =  glb_func_chkvl($_POST['complex']);
        $sts             =  glb_func_chkvl($_POST['lststs']);
        $dt              =  date('Y-m-d');
        $emp             =  $_SESSION['sesadmin'];

        $sqryquestion_info 
                        =  "SELECT candi_first
                            FROM question_info
                            WHERE candi_first='$first'";

    if(isset($_POST['frmtyp']) && ($_POST['frmtyp'] == "add"))
    {

            $srsquestion_info =mysql_query($sqryquestion_info);
            $rows         = mysql_num_rows($srsquestion_info);
            if($rows > 0)
            {
                $gmsg = "<font color=red size=2>Duplicate Candidate Name . Record not saved</font>";
            }
            else
            {
               $iqryquestion_info="insert into question_info(
                               candi_first,candi_last,date,
                               skill,subtype_1,
                               subtype_2,person_int,
                               comp_name,loc_int,complex_lvl,
                               type_int,question_candi,q_crton,
                               q_crtby)
                        values('$first','$last','$date','$skill','$sub1','$sub2','$person','$company',
                               '$location','$complex','$sts','$desc','$dt','$emp')";

                $irsquestion_info = mysql_query($iqryquestion_info);
                if($irsquestion_info==true)
                {
                    $gmsg = "<font color=green size=2>Record saved successfully</font>";
                }
                else
                {
                    $gmsg = "<font color=red size=2>Record not saved</font>";
                }
            }

        }   

    if(isset($_POST['frmtyp']) && ($_POST['frmtyp'] == "edit"))
    {
        $id           = $_REQUEST['hdnedit'];
        $pg           = $_REQUEST['hdnpg'];
        $countstart   = $_REQUEST['hdncntstrt'];


        $sqryquestion_info  .=" and ques_id !=$id";
        $srsquestion_info    = mysql_query($sqryquestion_info);
        $rows            = mysql_num_rows($srsquestion_info);
        if($rows > 0)
        {
        ?>
            <script>location.href="view_all_questions.php?sts=d&pg=<?php echo $pg;?>&countstart=<?php echo $countstart;?><?php echo $srchval;?>";</script>
        <?php
        }
        else
        {
             $uqryquestion_info="update question_info set 
                             date           ='$date',
                             candi_first    ='$first',
                             candi_last     ='$last',
                             skill          ='$skill',
                             subtype_1      ='$sub1',
                             subtype_2      ='$sub2',
                             person_int     ='$person',
                             comp_name      ='$company',
                             loc_int        ='$location',
                             complex_lel    ='$complex',
                             type_int       ='$company',
                             question_candi ='$desc',
                             q_mdfdon       ='$dt',
                             q_mdfdby       ='$emp' ";

             $uqryquestion_info .= " where ques_id=$id";                       


            $ursquestion_info = mysql_query($uqryquestion_info);
            if($ursquestion_info==true)
            {
            ?>
                <script>location.href="view_all_questions.php?sts=y&pg=<?php echo $pg;?>&countstart=<?php echo $countstart;?><?php echo $srchval;?>";  
                 </script>
            <?php
            }
            else
            {
            ?>
                <script>location.href="view_all_questions.php?sts=n&pg=<?php echo $pg;?>&countstart=<?php echo $countstart;?><?php echo $srchval;?>";     
                 </script>          
<?php 
            }
        }   

    }

/***********************************  End Editing ******************************************************/        

    }
?>

ここから編集用の「メイン ファイル」を開始します。

<?php   
    if(isset($_POST['sbmtbtn']) && ($_POST['sbmtbtn'] != ""))
        {

        $desc            =  strip_tags($_POST['txtdesc']);
        $date            =  glb_func_chkvl($_POST['txtdate']);
        $first           =  glb_func_chkvl($_POST['txtfirst']);
        $last            =  glb_func_chkvl($_POST['txtlast']);
        $skill           =  glb_func_chkvl($_POST['txtskill']);
        $sub1            =  glb_func_chkvl($_POST['txtsub1']);
        $sub2            =  glb_func_chkvl($_POST['txtsub2']);
        $person          =  glb_func_chkvl($_POST['txtperson']);
        $company         =  glb_func_chkvl($_POST['txtcompany']);
        $location        =  glb_func_chkvl($_POST['txtlocation']);
        $complex         =  glb_func_chkvl($_POST['complex']);
        $sts             =  glb_func_chkvl($_POST['lststs']);
        $dt              = date('Y-m-d');
        $emp             = $_SESSION['sesadmin'];

         $sqryquestion_info="select candi_first
                         from question_info
                         where candi_first='$first'";

    if(isset($_POST['frmtyp']) && ($_POST['frmtyp'] == "add"))
    {

            $srsquestion_info =mysql_query($sqryquestion_info);
            $rows         = mysql_num_rows($srsquestion_info);
            if($rows > 0)
            {
                $gmsg = "<font color=red size=2>Duplicate Candidate Name . Record not saved</font>";
            }
            else
            {
               $iqryquestion_info="insert into question_info(
                               candi_first,candi_last,date,
                               skill,subtype_1,
                               subtype_2,person_int,
                               comp_name,loc_int,complex_lvl,
                               type_int,question_candi,q_crton,
                               q_crtby)
                        values('$first','$last','$date','$skill','$sub1','$sub2','$person','$company',
                               '$location','$complex','$sts','$desc','$dt','$emp')";

                $irsquestion_info = mysql_query($iqryquestion_info);
                if($irsquestion_info==true)
                {
                    $gmsg = "<font color=green size=2>Record saved successfully</font>";
                }
                else
                {
                    $gmsg = "<font color=red size=2>Record not saved</font>";
                }
            }

        }   

    if(isset($_POST['frmtyp']) && ($_POST['frmtyp'] == "edit"))
    {
        $id           = $_REQUEST['hdnedit'];
        $pg           = $_REQUEST['hdnpg'];
        $countstart   = $_REQUEST['hdncntstrt'];


        $sqryquestion_info  .=" and ques_id !=$id";
        $srsquestion_info    = mysql_query($sqryquestion_info);
        $rows            = mysql_num_rows($srsquestion_info);
        if($rows > 0)
        {
        ?>
            <script>location.href="view_all_questions.php?sts=d&pg=<?php echo $pg;?>&countstart=<?php echo $countstart;?><?php echo $srchval;?>";</script>
        <?php
        }
        else
        {
             $uqryquestion_info="update question_info set 
                             date           ='$date',
                             candi_first    ='$first',
                             candi_last     ='$last',
                             skill          ='$skill',
                             subtype_1      ='$sub1',
                             subtype_2      ='$sub2',
                             person_int     ='$person',
                             comp_name      ='$company',
                             loc_int        ='$location',
                             complex_lel    ='$complex',
                             type_int       ='$company',
                             question_candi ='$desc',
                             q_mdfdon       ='$dt',
                             q_mdfdby       ='$emp' ";

             $uqryquestion_info .= " where ques_id=$id";                       


            $ursquestion_info = mysql_query($uqryquestion_info);
            if($ursquestion_info==true)
            {
            ?>
                <script>location.href="view_all_questions.php?sts=y&pg=<?php echo $pg;?>&countstart=<?php echo $countstart;?><?php echo $srchval;?>";  
                 </script>
            <?php
            }
            else
            {
            ?>
                <script>location.href="view_all_questions.php?sts=n&pg=<?php echo $pg;?>&countstart=<?php echo $countstart;?><?php echo $srchval;?>";     
                 </script>          
<?php 
            }
        }   

    }

/***********************************  End Editing ******************************************************/        

    }
?>
4

0 に答える 0