SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Confirm alert

  1. #1
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Confirm alert

    I have this code, when i click cancel it is suppsoed to run $query = "DELETE FROM `privatechat` WHERE `other` ='Prv'";
    mysql_query($query); but it dosnt the code does work i have tested it on a normal page without the javascript does anyone know why it not working.:

    <?php
    if ($privatechatqry[other]=="$username")
    {
    ?>
    <script type="text/javascript">
    var x=window.confirm("<?= $privatechatqry[starter] ?> has requested a private chat!")
    if (x)
    {

    }
    else
    {
    $query = "DELETE FROM `privatechat` WHERE `other` ='Prv'";
    mysql_query($query);
    }
    </script>
    <?
    }
    ?>
    Animated Chatrooms - www.121chatrooms.net

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,185
    Mentioned
    191 Post(s)
    Tagged
    2 Thread(s)

    javascript and PHP

    You have your PHP code mixed in with the javascript code. PHP is server-side and javascript is client-side. But it looks like the main problem is that you aren't going "in and out of" PHP <-> HTML, ie. the javascript, correctly.

  3. #3
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so how can i fix it?
    Animated Chatrooms - www.121chatrooms.net

  4. #4
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ah sorry my bad i fixed it but ok adn cancel are acting the same theya both do the same i only want it so when i press cancel it runs $query = "DELETE FROM `privatechat` WHERE `other` ='Prv'";
    mysql_query($query);
    Animated Chatrooms - www.121chatrooms.net

  5. #5
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,185
    Mentioned
    191 Post(s)
    Tagged
    2 Thread(s)

    javascript confirm

    You are confusing server-side with client-side.
    A javascript confirm(), eg.
    HTML Code:
    if(confirm("Confirm Test")){
    	alert("OK was clicked");
    }else{
    	alert("Cancel was clicked");
    }
    will run javascript code on the user's computer depending on whether OK was clicked or not. It will not run PHP code. Only the PHP parser on the server can do that.
    You could try putting in a form submit inside the Cancel's else block to send information to a PHP file on the server to run the query.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •