Jump to content

why is my echo '<script>alert("Cannot be deleted!")</script>'; is not working?


phpbigenner

Recommended Posts

<?php

$act = $rs['actorID'];

$m=mysql_query("SELECT * FROM movie_actor where actorID = '$act'");

$ma = mysql_num_rows($m);

if($ma!=0){

 

echo '<script>alert("Cannot be deleted!")</script>';

 

  }else{

 

echo '<td style="text-align:center"><a href="delete_actor.php?ID='.$row['actorID'].'" onclick="confirmation();return false"> <img height="40" width="40" src="icons/xx.png" /></a>

</td> ';

}

?>

Link to comment
Share on other sites

Does <script>alert("Cannot be deleted!")</script> actually get echoed if you view the page source after the page loads?  If it is there, what doctype are you using?  I am no pro javascript guy by any stretch of the meaning but I believe that in most doctypes besides html5 you need to specifiy type="text/javascript" in the <script>, not sure if not having that will make it not work but worth a try.

Link to comment
Share on other sites


<?php session_start();?>
<?php require_once("connect.php");?>
<?php 
if(isset($_COOKIE["header"])){
if($_COOKIE["header"]=="admin")
{
include("header_admin.php");
}
else
{
include("header_logout.php");
}






}
elseif($_COOKIE["header"]==NULL){
if($_SESSION['header']=="user"){
include("header_logout.php");
echo "<meta http-equiv='refresh' content='0;url=home.php'>";
}
elseif($_SESSION['header']=="admin"){


include("header_admin.php");


}
else{
include("header_login.php");
echo "<meta http-equiv='refresh' content='0;url=home.php'>";


}
}


?>




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="content-script-type" content="text/javascript"/>
<title>Star Theater</title>
<link rel="shortcut icon" href="images/favicon.ico" />
<link rel="stylesheet" media="screen" href="css/demo.css" />
<link rel="stylesheet" type="text/css" href="css/table.css"/>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
<!--
function confirmation() {


var msg = "Are you sure you want to delete this lead actor/actress?";
var answer = confirm(msg);
if (answer){
alert('Record successfully deleted!')
document.frm.submit();
}
}
   
</script>
<script>
function myFunction()
{
alert("ayus");
}
</script>
<style>
.highlighted { background:#090; }
</style>


</head>
     <body>


        <div id="content">
        
    
  <div align="right"><a href="f.actor_add.php" > <img src="icons/ad.png" width="70px" height="70px" title="Add new actor" /></a>
</div>




<table class="filterable" id="bordered">
    <thead>
              <tr>
        
          
        <th style="text-align:center">Lastname</th>
        <th style="text-align:center">Firstname</th>  
        <th style="text-align:center">Date of birth</th>      
        <th style="text-align:center">Contact number</th>
        <th style="text-align:center">Address</th>
         <th style="text-align:center">VIEW</th>
        <th style="text-align:center">EDIT</th>
        <th style="text-align:center">DELETE</th>
    </tr>
            </thead>
            <tbody>
<?php
include('conn.php');


        $result = mysql_query("SELECT * FROM actor order by lname")or die(mysql_error());  
        while($row = mysql_fetch_array( $result )) {
                
                echo "<tr>";
                echo '<td>' . $row['lname'] . '</td>';
echo '<td>' . $row['fname'] .'</td>';
echo '<td style="text-align:right">' . $row['dob'] . '</td>';
echo '<td style="text-align:right">' . $row['contact_no'] . '</td>';
echo '<td>' . $row['address'] . '</td>';
echo '<td style="text-align:center"><a href="view_actor.php?ID='.$row['actorID'].'"><img height="40" width="40" src="icons/view.png"/></a>
        </td> ';
echo '<td style="text-align:center"><a href="f.actor_edit.php?ID='.$row['actorID'].'"><img height="40" width="40" src="icons/ed.png" /></a>
        </td> ';


$act = $rs['actorID'];
$m=mysql_query("SELECT * FROM movie_actor where actorID = '$act'");
$ma = mysql_num_rows($m);
if($ma!=0){


echo '<script type="text/javascript">alert("Cannot be deleted!")</script>';


  }else{


echo '<td style="text-align:center"><a href="delete_actor.php?ID='.$row['actorID'].'" onclick="confirmation();return false"> <img height="40" width="40" src="icons/xx.png" /></a>
</td> ';
}
                echo "</tr>";}?>
                
 </tbody>
        </table>
 <script type="text/javascript" src="js/tablesearch.js"></script>
     </div><!-- /content -->
     
     
        <div id="footer">
           <label>© <a href="https://www.facebook.com/CodeWEBB.Design?fref=ts">CodeWEBB Design</a></label> |<a href="developers.php"> Developers</a>
           
        </div><!-- /footer -->
   
    </body>
</html>
Edited by Maq
Link to comment
Share on other sites

I don't see anything that stands out as an issue in your code.  Again, are you sure that <script> tags are actually being echoed to the page?  Run your page in the browser and then do a view page source and see if they are in there.  You could also post the view source result here and we can take a look.

Link to comment
Share on other sites

 

 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">   <head>   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />   <title>Star Theater</title>   <link rel="shortcut icon" href="images/favicon.ico" />   <link rel="stylesheet" media="screen" href="css/demo.css" />   </head>   <body>   <div id="demo-header">   <a id="login-link" href="logout_process.php" title="Logout">Logout</a>   <div id="login-panel">       </div><!-- /login-panel -->   </div><!-- /demoheader -->   <br class="clear" /><br /><br /><br />   <div id="content">       <h1 class="pagehead"></h1>               <ul id="menu">   <li><a href="home.php">Home</a></li>   <li><a href="#">Maintenance</a>   <ul>   <li><a href="theater.php">Theater</a></li>   <li><a href="director.php">Director</a></li>   <li><a href="actor.php">Lead Actor/Actress</a></li>   <li><a href="genre.php">Genre</a></li>   <li><a href="schedule.php">Time Scheduling</a></li>   <li><a href="price.php">Price</a></li>   <li><a href="movie.php">Movie</a></li>   <li><a href="viewer.php">Viewer</a></li>   <li><a href="slideshow.php">Slide Show</a></li>   </ul>   </li>   <li><a href="#">Transactions</a>   <ul>   <li><a href="reservation.php">Reservation</a></li>   <li><a href="billing.php">Billing</a></li>   <li><a href="waitlist.php">Wait list</a></li>   </ul>   </li>   <li><a href="#">Utility</a>   <ul>   <li><a href="user.php">User</a></li>   <li><a href="discount.php">Discount</a></li>   </ul>   </li>   <li><a href="#">Reports</a>   <ul>   <li><a href="sale.php">Sales</a></li>   </ul>   </li>   <li><a href="faq">Frequently Ask Questions</a></li>   <li><a href="about.php">About Us</a></li>           </ul>   </div><!-- /content -->   <!--</div>    </div>    -->       </body>   </html>       <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   <html xmlns="http://www.w3.org/1999/xhtml">   <head>   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />   <title>Star Theater</title>   <link rel="shortcut icon" href="images/favicon.ico" />   <link rel="stylesheet" media="screen" href="css/demo.css" />   <link rel="stylesheet" type="text/css" href="css/table.css"/>   <script type="text/javascript" src="js/jquery.js"></script>   <script type="text/javascript">   <!--   function confirmation() {       var msg = "Are you sure you want to delete this lead actor/actress?";   var answer = confirm(msg);   if (answer){   alert('Record successfully deleted!')   document.frm.submit();   }   }       </script>   <style>   .highlighted { background:#090; }   </style>       </head>   <body>       <div id="content">           <div align="right"><a href="f.actor_add.php" > <img src="icons/ad.png" width="70px" height="70px" title="Add new actor" /></a>   </div>           <table class="filterable" id="bordered">   <thead>   <tr>           <th style="text-align:center">Lastname</th>   <th style="text-align:center">Firstname</th>   <th style="text-align:center">Date of birth</th>   <th style="text-align:center">Contact number</th>   <th style="text-align:center">Address</th>   <th style="text-align:center">VIEW</th>   <th style="text-align:center">EDIT</th>   <th style="text-align:center">DELETE</th>   </tr>   </thead>   <tbody>   <tr><td>adf</td><td>jake</td><td style="text-align:right">07/11/2013</td><td style="text-align:right">321</td><td>das</td><td style="text-align:center"><a href="view_actor.php?ID=4"><img height="40" width="40" src="icons/view.png"/></a>   </td> <td style="text-align:center"><a href="f.actor_edit.php?ID=4"><img height="40" width="40" src="icons/ed.png" /></a>   </td> <td style="text-align:center"><a href="delete_actor.php?ID=4" onclick="confirmation();return false"> <img height="40" width="40" src="icons/xx.png" /></a>   </td> </tr>   </tbody>   </table>   <script type="text/javascript" src="js/tablesearch.js"></script>   </div><!-- /content -->           <div id="footer">   <label>© <a href="https://www.facebook.com/CodeWEBB.Design?fref=ts">CodeWEBB Design</a></label> |<a href="developers.php"> Developers</a>       </div><!-- /footer -->       </body>   </html>
 
Edited by phpbigenner
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.