编辑按钮得到的帖子在php中没有工作

时间:2018-03-08 03:35:19

标签: php

我在php上非常糟糕,所以我需要帮助。我创建了一个搜索html表,我想包括每行的编辑和删除按钮。单击编辑按钮后,它将重定向到用户更新数据的编辑页面。我尝试了</form>". if (isset($_POST['edit'])) { $id=$_POST['id']; echo "<script language='javascript'> window.location.href='admin_edit.php?id=$id'</script>"; }.",但语法错误,意外发生,如果&#39;下面的代码也无效。

&#13;
&#13;
if(isset($_POST['searchq']) && $_POST['searchq'] != "")
{
    if(isset($_POST['searchopt']) && $_POST['searchopt'] != "")
    {
        $escsearch = mysqli_real_escape_string($conn, $_POST['searchq']);
        $searchval = preg_replace('#[^a-z 0-9]#i', '', $escsearch);
        $opt = $_POST['searchopt'];

        switch($opt)
        {
            case "dpt":
            $query = "SELECT * FROM coi_system where department LIKE '%$searchval%'";
            $res = mysqli_query($conn, $query) or die(mysqli_error());
            $count = mysqli_num_rows($res);
            if($count > 0)
           {

            while($row = mysqli_fetch_array($res))
            {
                $accountcode = $row['accountcode'];
                $department = $row['department'];
                $person_in_charge = $row['person_in_charge'];
                $project_title = $row['project_title'];
                $objective = $row['objective'];
                $how_to_do = $row['how_to_do'];
                $activities = $row['activities'];
                $project_started = $row['project_started'];
                $project_completed = $row['project_completed'];
                $target_cost_saving = $row['target_cost_saving'];
                $costsaving_afterjustification = $row['costsaving_afterjustification'];
                $costsaving_monthly = $row['costsaving_monthly'];
                $sum_of_month = $row['sum_of_month'];
                $avg_monthly_saving = $row['avg_monthly_saving'];
                $todays_date = $row['todays_date'];
                $current_month = $row['current_month'];
                $targetsaving_currentmonth = $row['targetsaving_currentmonth'];
                $id = $row['id'];
            $output = "$count results for <strong>$escsearch</strong>.";
       echo "<html>
              <table><thead>
                <tr>
                  <th rowspan='2'><div>No Seq</div></th>
                  <th rowspan='2'><div>Account Code</div></th>
                  <th rowspan='2'><div>Department</div></th>
                  <th rowspan='2'><div>Person in charge</div></th>
                  <th rowspan='2'><div>Project title</div></th>
                  <th rowspan='2'><div>Objective</div></th>
                  <th rowspan='2'><div>How To Do</div></th>
                  <th rowspan='2'><div>Activities</div></th>
                  <th rowspan='2'><div>Project Started</div></th>
                  <th rowspan='2'><div>Project Completed</div></th>
                  <th rowspan='2'><div>Target Cost Saving</div></th>
                  <th rowspan='2'><div>Cost Saving After Justification</div></th>
                  <th colspan='12'><div>Cost Saving Monthly</div></th>
                  <th rowspan='2'><div>Sum as of the Month</div></th>
                  <th rowspan='2'><div>AVG Monthly Saving</div></th>
                  <th rowspan='2'><div>Today's Date</div></th>
                  <th rowspan='2'><div>Current Month</div></th>
                  <th rowspan='2'><div>Var.</div></th>
                  <th rowspan='2'><div>Target Saving as of the Current Month</div></th>
                  <th><div> </div></th>
                </tr>

                <tr>
                  <th><div> Jan 17</div></th>
                  <th><div> Feb 17 </div></th>
                  <th><div> Mac 17</div></th>
                  <th><div> April 17</div></th>
                  <th><div> Mei 17</div></th>
                  <th><div> Jun 17</div></th>
                  <th><div> Julai 17</div></th>
                  <th><div> Ogos 17</div></th>
                  <th><div> Sept 17</div></th>
                  <th><div> Oct 17</div></th>
                  <th><div> Nov 17</div></th>
                  <th><div> Dis 17</div></th>
                </tr>
                </thead>";
            while($row = mysqli_fetch_array($res))
            {
                $accountcode = $row['accountcode'];
                $department = $row['department'];
                $person_in_charge = $row['person_in_charge'];
                $project_title = $row['project_title'];
                $objective = $row['objective'];
                $how_to_do = $row['how_to_do'];
                $activities = $row['activities'];
                $project_started = $row['project_started'];
                $project_completed = $row['project_completed'];
                $target_cost_saving = $row['target_cost_saving'];
                $costsaving_afterjustification = $row['costsaving_afterjustification'];
                $costsaving_monthly = $row['costsaving_monthly'];
                $sum_of_month = $row['sum_of_month'];
                $avg_monthly_saving = $row['avg_monthly_saving'];
                $todays_date = $row['todays_date'];
                $current_month = $row['current_month'];
                $targetsaving_currentmonth = $row['targetsaving_currentmonth'];
                $id = $row['id']; 

          echo "
                  <tr>
                    <td> <div> </div> </td>
                    <td><div>$accountcode</div></td>
                    <td><div>$department</div></td>
                    <td><div>$person_in_charge</div></td>
                    <td><div>$project_title</div></td>
                    <td><div>$objective</div></td>
                    <td><div>$how_to_do</div></td>
                    <td><div>$activities</div></td>
                    <td><div>$project_started</div></td>
                    <td><div>$project_completed</div></td>
                    <td><div>$target_cost_saving</div></td>
                    <td><div>$costsaving_afterjustification</div></td>
                    <td><div></div></td>
                    <td><div></div></td>
                    <td><div></div></td>
                    <td><div></div></td>
                    <td><div></div></td>
                    <td><div></div></td>
                    <td><div></div></td>
                    <td><div></div></td>
                    <td><div></div></td>
                    <td><div></div></td>
                    <td><div></div></td>
                    <td><div></div></td>
                    <td><div>$sum_of_month </div></td>
                    <td><div>$avg_monthly_saving </div></td>
                    <td><div>$todays_date </div></td>
                    <td><div>$current_month </div></td>
                    <td><div></div></td>
                    <td><div>$targetsaving_currentmonth</div></td>
                    <td>
                      <form method='post'>
                        <button id='1' name='button'>BUTTON 1</button>
                          <input type='hidden' name='id' value='<?php echo $id; ?>'>
                      </form>
                      if (isset($_POST['edit'])) {
    $id=$_POST['id'];
  echo '<script language='javascript'> window.location.href='admin_edit.php?id=$id'</script>';
  }
                      <form method='post'>
                        <input type='hidden' name='id' value='<?php echo $id; ?>'>
                          <button type='submit' name='delete' id='delete' class='delete'>
                            <span>Delete</span>
                        </button>
                      </form>
                    </td>
                  </tr>
                </html>";
            }
        }else{
            $output = "<tr><td>No records found.</td></tr>"; 
        }
    echo "</table>";
        
            break;
        }
    }
}
?>
<?php
}
?>
<?php
  if (isset($_POST['delete'])) {
    $id=$_POST['id'];
  mysqli_query($conn, "DELETE FROM coi_system WHERE id='$id'");
  echo "<script language='javascript'> window.location.href='admin_table.php'</script>";
} ?>
&#13;
&#13;
&#13;

提前谢谢!

0 个答案:

没有答案