最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - How to close window by clicking CANCEL button? - Stack Overflow

programmeradmin2浏览0评论

this php file will be opened as a pop-up window by clicking a button on other file. I included 2 buttons in this file, one for UPDATE and another for CANCEL. If user click on UPDATE data will be updated in databse.I want to close window automatically if user click on CANCEL button. But what's happening is if user clicks on CANCEL button, window is closing but data is getting updated in database. What should I do in-order to close the window without getting the data updated in database? Thanks for the help in advance.

    `<html>
     <head>

    <link rel="stylesheet" type="text/css" href="cms_style.css">    


 </head>

  <body>


  <?php

        $cid = $_GET['id'];
        $uid = $_GET['uid'];



    $con = mysql_connect("localhost", "root", "");
    mysql_select_db("abcd",$con);


    if($uid==1) {

        updateRecord($cid);



    } else if (isset($_GET['id']) ) {


        $ResumeID = $_GET['id']; 
        $sql="SELECT * from data WHERE ResumeID=$ResumeID";
        $result = mysql_query($sql);
        $Row=mysql_fetch_row($result); 


 ?> 
     <form align="center" action="update.php?id=<? echo "$Row[1]"?>&uid=1"
                          method="post">
    <table align="center">
        <input type="hidden" name="resumeid" value="<? echo "$Row[1]"?>">

    <? echo "<tr> <td> Resume ID </td><td>$Row[1]</td> </tr>" ?>                         

   <div align="center">
   <tr><td> Name of the Candidate</td>
  <td><input type="text" name="NameoftheCandidate" size="25" value="<? echo            
       "$Row[0]" ?>">   </td>
  </tr>

 <tr>
 <td>TelephoneNo</td>
      <td><input type="text" name="TelephoneNo" size="25" value="<? echo "$Row[2]"?     
      >">            

        </td>
     </tr>
    <tr>       
    <td>Email</td>
<td><input type="text" name="Email" size="25" value="<? echo "$Row[3]"?>">
    </td>

    <tr>
    <td></td>
<td align="center"><input type="submit" name="submitvalue" value="UPDATE" ></td>
<td align="center"><input type="submit" name="cancelvalue" value="CANCEL"         
     onClick="self.close()"></td>
    </tr>
    </div>                              
    </table>
    </form>

<?php
    } // end of else if



    function updateRecord($cid) {


          $sql="UPDATE data SET 
          NameoftheCandidate=\"$_POST[NameoftheCandidate]\",
         TelephoneNo='$_POST[TelephoneNo]',
          Email='$_POST[Email]' WHERE ResumeID=$_GET[id]";



        if(mysql_query($sql))
            echo "<p>Record updated Successfully</p>";
        else
            echo "<p>Record update failed</p>";


    } // end of update function


      ?>



     </body>
         </html>`

this php file will be opened as a pop-up window by clicking a button on other file. I included 2 buttons in this file, one for UPDATE and another for CANCEL. If user click on UPDATE data will be updated in databse.I want to close window automatically if user click on CANCEL button. But what's happening is if user clicks on CANCEL button, window is closing but data is getting updated in database. What should I do in-order to close the window without getting the data updated in database? Thanks for the help in advance.

    `<html>
     <head>

    <link rel="stylesheet" type="text/css" href="cms_style.css">    


 </head>

  <body>


  <?php

        $cid = $_GET['id'];
        $uid = $_GET['uid'];



    $con = mysql_connect("localhost", "root", "");
    mysql_select_db("abcd",$con);


    if($uid==1) {

        updateRecord($cid);



    } else if (isset($_GET['id']) ) {


        $ResumeID = $_GET['id']; 
        $sql="SELECT * from data WHERE ResumeID=$ResumeID";
        $result = mysql_query($sql);
        $Row=mysql_fetch_row($result); 


 ?> 
     <form align="center" action="update.php?id=<? echo "$Row[1]"?>&uid=1"
                          method="post">
    <table align="center">
        <input type="hidden" name="resumeid" value="<? echo "$Row[1]"?>">

    <? echo "<tr> <td> Resume ID </td><td>$Row[1]</td> </tr>" ?>                         

   <div align="center">
   <tr><td> Name of the Candidate</td>
  <td><input type="text" name="NameoftheCandidate" size="25" value="<? echo            
       "$Row[0]" ?>">   </td>
  </tr>

 <tr>
 <td>TelephoneNo</td>
      <td><input type="text" name="TelephoneNo" size="25" value="<? echo "$Row[2]"?     
      >">            

        </td>
     </tr>
    <tr>       
    <td>Email</td>
<td><input type="text" name="Email" size="25" value="<? echo "$Row[3]"?>">
    </td>

    <tr>
    <td></td>
<td align="center"><input type="submit" name="submitvalue" value="UPDATE" ></td>
<td align="center"><input type="submit" name="cancelvalue" value="CANCEL"         
     onClick="self.close()"></td>
    </tr>
    </div>                              
    </table>
    </form>

<?php
    } // end of else if



    function updateRecord($cid) {


          $sql="UPDATE data SET 
          NameoftheCandidate=\"$_POST[NameoftheCandidate]\",
         TelephoneNo='$_POST[TelephoneNo]',
          Email='$_POST[Email]' WHERE ResumeID=$_GET[id]";



        if(mysql_query($sql))
            echo "<p>Record updated Successfully</p>";
        else
            echo "<p>Record update failed</p>";


    } // end of update function


      ?>



     </body>
         </html>`
Share Improve this question edited Mar 19, 2013 at 8:30 aidan 9,5769 gold badges71 silver badges85 bronze badges asked Mar 19, 2013 at 8:13 trendzcreatortrendzcreator 352 gold badges4 silver badges8 bronze badges 1
  • 1 BTW, you should provide resulting static HTML code, not your source PHP+HTML code. – Marat Tanalin Commented Mar 19, 2013 at 8:16
Add a ment  | 

3 Answers 3

Reset to default 3

change type="submit" to "button"

<td align="center">
<input type="submit" name="submitvalue" value="UPDATE" >
</td>
<td align="center">
<input type="button" name="cancelvalue" value="CANCEL" onClick="self.close()"> 
</td>

Try adding return false; after calling self.close(). Alternatively, you can replace <input type="submit"> to <input type="button">.

Something like this could work.

<?php

if (!empty($_POST['cancelvalue'])){
exit();
}

?>

Buttons client-side won't stop a script server side.

Something else, you can't use isset to check for the global arrays, if any values are passed the array will return true. You should use empty instead.

发布评论

评论列表(0)

  1. 暂无评论