SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot
    Join Date
    May 2008
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    popup window opens when page loads

    hi, I have html and php code on 1 page.
    The html code is the form input code and the php code inserts the inputs to the database. when the form input is successful a popup window open saying successful and when an input is not successful a popup window shows saying not successful. However when the page loads/refreshes the popup window opens at the same time without submiting anything to the php code. window that opens is the one for the input not being successful.
    PHP Code:
    PHP Code:
    <html> 
    <form action="http://localhost/removep.php" method="post"> 
     <input name="num" id="num" type="text" title="required" maxlength="10"/> 
     <input type="submit" name="remove" value="  Remove  "/> 
    </form> 
    </html> 

    <?php 

    database connection code
    ..//works fine 

    $num $_POST['num']; 

    if(
    $num !=''


    mysql_query("DELETE FROM job WHERE num1 ='$num'"); 
    $check=mysql_affected_rows();

    if(
    $check>0)  
    ?> 
    <html><body><SCRIPT type="text/javascript"> 
    window.open('http://localhost/popup-removed.html',"removed","width=250,height=150");</SCRIPT></body></html> 
    <?php  
    }  
    else 
    ?> 
    <html><body><SCRIPT type="text/javascript">  
    window.open('http://localhost/popup-notremoved.html',"not_removed","width=250,height=150");</SCRIPT></body></html>  
    <?php 


    ?>

    i have tried using elseif(!$check>0) instead of else but the window still opens. when the page loads without submitting anything to the database the result variable show with a value of 0.

    Please i really need help, i have tried everthing i know off and can not get the window to stop opening when pages loads or is refreshed.

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Your 'else' is always going to run, unless the delete was successful of course.

    You need an additional check before your conditional:-

    PHP Code:
    <?php
    if(isset($_POST) && is_int($_POST['num']))
    {
        
    mysql_query(sprintf('DELETE FROM job WHERE num1 = %s'$_GET['num']));
        if(
    mysql_affected_rows() > 0)
        {
            
    ?>
            <html>
            <body>
            <SCRIPT type="text/javascript">window.open('http://localhost/popup-removed.html',"removed","width=250,height=150");</SCRIPT>
            </body>
            </html>
            <?php
        
    }
        else
        {
            
    ?>
            <html>
            <body>
            <SCRIPT type="text/javascript">window.open('http://localhost/popup-notremoved.html',"not_removed","width=250,height=150");</SCRIPT>
            </body>
            </html>
            <?php
        
    }
    }
    ?>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    SitePoint Zealot
    Join Date
    May 2008
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if i have made my code same as what you have posted other than i have not added %s', $_GET['num'])); line it was causing an error. and things do not seem to be working now. the input value does not seem to be getting through to the query.

  4. #4
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    My bad! Sorry.

    PHP Code:
    <?php
    if(isset($_GET['num']) && is_int($_GET['num']))
    {
        
    mysql_query(sprintf('DELETE FROM job WHERE num1 = %s'mysql_escape_string($_GET['num'])));
        if(
    mysql_affected_rows() > 0)
        {
            
    ?>
            <html>
            <body>
            <SCRIPT type="text/javascript">window.open('http://localhost/popup-removed.html',"removed","width=250,height=150");</SCRIPT>
            </body>
            </html>
            <?php
        
    }
        else
        {
            
    ?>
            <html>
            <body>
            <SCRIPT type="text/javascript">window.open('http://localhost/popup-notremoved.html',"not_removed","width=250,height=150");</SCRIPT>
            </body>
            </html>
            <?php
        
    }
    }
    ?>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  5. #5
    SitePoint Zealot
    Join Date
    May 2008
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi that does not work, the popup windows do not open at all.

  6. #6
    SitePoint Zealot
    Join Date
    May 2008
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    does anybody have any other solutions please

  7. #7
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,784
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    When the page is refreshed the HTML that was sent to the browser will reload into the browser. The server side processing doesn't get rerun at all.Most browsers will not display your popups because most popup blockers require a user action to request a popup. You'd do better to just incorporate the response into the page where it will be more obvious that refreshing the page just redisplays the content without anything actually getting run.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


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
  •