drhanjuw56233 2015-03-22 08:53
浏览 21
已采纳

使用php中的编辑和删除图像删除和更新行

This is my branch.php page and I want to delete and update row when the user click on the edit and delete image in php and directly the row should be deleted or updated in the table.But It is not working neither row is getting updated or deleted.

<?php
$a1=mysql_connect('localhost','root1','oec@123');
$b1=mysql_select_db('rms',$a1);
?> 
  <!doctype html>
  <html>
  <head>
  <meta charset="utf-8">
    <title>branch</title>
     <link href="styles/branch.css" rel="stylesheet" type="text/css">
     </head>

      <body>

   <div id="wrapper">
   <header id="top">
   <h1>Reporter Management System</h1>
    <nav id="mainnav">
    <ul>
    <li><a href="admin.php">Home</a></li>
    <li><a href="branch.php">Branch</a></li>
    <li><a href="branchadmin.php">Branch Admin</a></li>
    <li><a href="reporter.php">Reporters</a></li>
    <li><a href="accountant.php">Accountant</a></li>
    <li><a href="setting.php">Settings</a></li>
    <li><a href="">Log out</a></li>
    </ul>
    </nav>
    </header>
    <div id="hero">
    <img src="News2.jpg" width="1000" height="320"  alt=""/>  </div>
    <form  role="form"  action ="searchbranch.php" method="post">
    <p><label for="Search">Search Branch :</label>
    <input class="textbox" type="Search" placeholder="Name" name="Search">
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="submit"  class="classname" value="Search" >

       </form>
      <form role= "form" action="createbranch.php" method="post">
       <input type="submit"  class="classname" value="Add Branch"                       onClick="href 'createbranch.php' " ></p>
       </form>
        <section class="page container">
        <div>
       <div class="span12">
       <div class="box pattern ">
       <div class="box-header">
        <i class="icon-list"></i>

        </div>
        <table id="sample-table" class="table table-hover table-bordered  tablesorter">
          <thead>
         <tr>
         <th>Sl no</th>
         <th>Branch</th>
         <th>Description</th>
         <th>Action</th>
          </tr>
          <?php
          $w='SELECT Sl_no, branch, description from create_branch;';
          $recordset=mysql_query($w,$a1) or die(mysql_error());

          $totalrows=mysql_num_rows($recordset);
          $row_recordset=mysql_fetch_assoc($recordset);
          if($totalrows>0)
          {
           do
          {
         $r=$row_recordset['Sl_no'];
         $d=$row_recordset['branch'];
         $d1=$row_recordset['description'];

         ?>
        </thead>
        <tbody id='tb-content'>
         <tr>
         <td><?php echo $r ;?></td>
         <td><?php echo $d ;?></td>
         <td><?php echo $d1 ;?></td>
         <td> <?php echo  '
         <a  href="edit_branch.php?no='.$row_recordset['Sl_no'].'">'?>
        <img src="pencil.png" />
        <?php   '</a>';? >&nbsp;|&nbsp;<?php echo' 
        <a href="branch_delete.php?no1='.$row_recordset['branch'].'">'?>
        <img src="cross.png" /> <?php '</a>';?>  
         </td>
          </tr>
          <?php    
         }while($row_recordset=mysql_fetch_assoc($recordset));
         }
         mysql_free_result($recordset);
          mysql_close($a1);
          ?>

          </tbody>
           </table>
           </div>
           </div>
           </div>
           </section>
            </body>
              <footer>
           <p>&nbsp;</p><hr>
           <center>&copy;Copyright 2015 RepoterManagnmentSystem
           </center> 
           </footer>
            </div>
            </body>
            </html>

This is branch_delete.php

  <?php
  $cn=mysql_connect('localhost','root1',"oec@123");
  $db_selected=mysql_select_db('rms',$cn);
  $bn=$_REQUEST['no1'];
  $sql='DELETE     au.Sl_no,au.name,au.company_name,au.email_id,au.password,au.confirm_password,au.group,au.branch,au.phone,au.wordcount,au.rating,cb.Sl_no,cb.branch,cb.description from admin_user  au,create_branch  cb where cb.branch="'.$bn.'" AND au.branch=cb.branch ;';
    $s1=mysql_query($sql,$cn);
    mysql_close($cn);
    header('Location: branch.php');
     ?> 

This is update_branch.php

   <?php
   $a1=mysql_connect('localhost','root1','oec@123');
   $b1=mysql_select_db('rms',$a1);
   $bn=$_REQUEST['bname'];
   $sn=$_REQUEST['Sl_no'];
   $d=$_REQUEST['descp'];
   $w= 'SELECT branch,description FROM create_branch;';
   $recordset=mysql_query($w,$a1) or die(mysql_error());
   $totalrows=mysql_num_rows($recordset);
   $row_recordset=mysql_fetch_assoc($recordset);
   if($totalrows>0)
   {
   do
     {
   $r=$row_recordset['branch'];
    $s=$row_recordset['description'];   
   if($bn==$r and $d==$s)
   {
    ?>

    <!doctype html>
    <html>
     <head>
      <meta charset="utf-8">
      <title>Untitled Document</title>
     <link href="styles/createbranch.css" rel="stylesheet" type="text/css">         
     </head>

       <body>

      <div id="wrapper">
       <header id="top">
       <h1>Reporter Management System</h1>
        <nav id="mainnav">
        <ul>
        <li><a href="index.html">Home</a></li>
        <li><a href="">Branch</a></li>
        <li><a href="">Branch Admin</a></li>
        <li><a href="">Reporters</a></li>
        <li><a href="">Accountant</a></li>
        <li><a href="">Settings</a></li>
        <li><a href="">Log out</a></li>
        </ul>
        </nav>
        </header>
        <div id="hero">
         <img src="News2.jpg" width="1000" height="320"  alt=""/>
          </div>

            <form  method="post" action="edit_branch.php">
          <article id="main">

        <?php echo '<h2>branch already exists</h2>' ; ?>

         <h2>Create Branch</h2><hr>
         <p><label for="branch name">Branch Name:</label><br><br>
         <input class="textbox" type="text" placeholder=" <?php echo $bn ;?>" name="bname"></p><br>
         <p><label for="Description">Description:</label><br><br>
         <input class="textbox" type="text" placeholder="<?php echo $d ;?>" name="descp"></p><br>
        <input type="submit"  class="classname" value="Update Branch" ></p>           <br>
      </article>
      </form>
      <footer>
      <p>&nbsp;</p><hr>
      <center> &copy; Copyright 2015 ReporterManagementSystem</center>           </footer>
      </div>
      </body>
      </html>
      <?php 

     exit(0);
         }
          }
     while($row_recordset=mysql_fetch_assoc($recordset));

     $w1='UPDATE create_branch set branch="'.$bn.'" and description="'.$d.'" where Sl_no="'.$sn.'";';
     $x=mysql_query($w1,$a1) or die(mysql_error());

     ?>
        <!doctype html>
        <html>
        <head>
        <meta charset="utf-8">
        <title>Untitled Document</title>

        </head>

        <body>
        <div id="wrapper">
        <header id="top">
        <h1>Reporter Management System</h1>
        <nav id="mainnav">
        <ul>
        <li><a href="branchadmin.php">Home</a></li>
        <li><a href="reporters.php">Reporters</a></li>
        <li><a href="content1.php">News Content</a></li>
        <li><a href="CreateUser.php">Add user</a></li>
        <li><a href="">Log Out</a></li>

        </ul>
        </nav>
        </header>
        <img src="News2.jpg" width="1000" height="320"  alt=""/>




        <?php
         echo "<br>";

       if($x=="true")
        {

        header('Location: branch.php');


        }
        else
        {
        echo "fail to update branch";
        }

        echo"<br>";

        }
        mysql_free_result($recordset);
        mysql_close($a1);
        ?>
  • 写回答

1条回答 默认 最新

  • dreamice2013 2015-03-22 10:47
    关注

    The sql query incorrectly built. To update an SQL query should look like this

    UPDATE table_name SET
           column1=value1,column2=value2,...
         WHERE some_column=some_value;
    

    Your update:

    UPDATE create_branch SET 
           branch="'.$bn.'" ,
           description="'.$d.'"
        WHERE Sl_no="'.$sn.'"
    

    Sql query - delete:

    DELETE FROM table_name
    WHERE some_column=some_value;
    

    Your delete:

    DELETE FROM create_branch
            WHERE cb.branch="'.$bn.'"
    

    Read MySQL documentation about FOREIGN KEY Constraints.

    In the case of two tables joined the foreign key, delete or modify a record in the first result will be an appropriate operation on record in the second table.

    Example: MySQL Foreign Key On Delete

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog