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 echarts动画效果失效的问题。官网下载的例子。
  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加