Our new Indie Games subforum is now open for business in G&T. Go and check it out, you might land a code for a free game. If you're developing an indie game and want to post about it, follow these directions. If you don't, he'll break your legs! Hahaha! Seriously though.
Our rules have been updated and given their own forum. Go and look at them! They are nice, and there may be new ones that you didn't know about! Hooray for rules! Hooray for The System! Hooray for Conforming!

[HTML/PHP] Pop-ups & forms

13»

Posts

  • guarguar Registered User regular
    Would that go in index.php, which calls delete.php, or in delete.php ?

  • InfidelInfidel It's not Infidel, it's INNNNNFIDELRegistered User regular
    That would go wherever you want when you need to redirect, instead of printing HTML.

    Depends on how you designed your code! :lol:

    edit: here's the general form of having a one-shot form/post window,
    if (isset($_POST['submit']))
    {
        // do my deleting in the database here
        // then HTTP redirect to the window close
        header('Location: closewin.html');
    }
    else
    {
    ?>
    <html>
    ...
    <form method="post">
    <input name="submit" type="submit" value="Delete">
    </form>
    ...
    </html>
    <?
    }
    

    Play D&D 4e? :: Check out Orokos and upload your Character Builder sheet! :: Orokos Dice Roller
    The PhalLounge :: Chat board for Phalla discussion and Secret Santas :: PhallAX 2013
    Critical Failures IRC! :: #CriticalFailures and #mafia on irc.slashnet.org
  • guarguar Registered User regular
    Maybe I'm not understanding, but to illustrate:

    delete.php
    <?php
        header('Location: http://localhost/index.php');
    
        $link = mysql_connect('localhost', 'root', '******');
        $db = mysql_select_db('backlog');
    
        $table = sprintf("&#37;s", mysql_real_escape_string($_GET[table]));
        $id = sprintf("%s", mysql_real_escape_string($_GET[id]));;
    
        mysql_query("DELETE FROM $table WHERE id = $id");
    
        mysql_close($link);
    ?>
    

  • SeguerSeguer Registered User regular
    In the page that you submit the form to you can have that close the window.

    So if update.php submits to itself and you have code that checks for a form submission, once you've done all the updates you just echo html that will close that window instead of redirecting or going to some other page. Any javascript you echo there should be able to refresh the parent (index.php or whatever opened the popup) and then close itself.

  • InfidelInfidel It's not Infidel, it's INNNNNFIDELRegistered User regular
    guar wrote: »
    Maybe I'm not understanding, but to illustrate:

    delete.php
    <?php
        header('Location: http://localhost/index.php');
    
        $link = mysql_connect('localhost', 'root', '******');
        $db = mysql_select_db('backlog');
    
        $table = sprintf("%s", mysql_real_escape_string($_GET[table]));
        $id = sprintf("%s", mysql_real_escape_string($_GET[id]));;
    
        mysql_query("DELETE FROM $table WHERE id = $id");
    
        mysql_close($link);
    ?>
    

    Oh god, why is your table a variable?? :lol:

    Also, there sprintf's are totally doing nothing.
    $id = intval($_GET['id']);
    
    mysql_query("DELETE FROM mytable WHERE id = $id");
    

    Also, I recommend putting the redirect as the last line, after processing. As mentioned by another earlier, you should do all your processing, then do your output. In this case, your output is simply the redirect header.

    Play D&D 4e? :: Check out Orokos and upload your Character Builder sheet! :: Orokos Dice Roller
    The PhalLounge :: Chat board for Phalla discussion and Secret Santas :: PhallAX 2013
    Critical Failures IRC! :: #CriticalFailures and #mafia on irc.slashnet.org
  • xzzyxzzy Registered User regular
    Putting the redirect at the bottom also means you'll see errors in the web browser, which is helpful for testing.

  • guarguar Registered User regular
    Infidel wrote: »
    guar wrote: »
    Maybe I'm not understanding, but to illustrate:

    delete.php
    <?php
        header('Location: http://localhost/index.php');
    
        $link = mysql_connect('localhost', 'root', '******');
        $db = mysql_select_db('backlog');
    
        $table = sprintf("%s", mysql_real_escape_string($_GET[table]));
        $id = sprintf("%s", mysql_real_escape_string($_GET[id]));;
    
        mysql_query("DELETE FROM $table WHERE id = $id");
    
        mysql_close($link);
    ?>
    

    Oh god, why is your table a variable?? :lol:

    Table, aka system name. I need to pass it to identify which table is being modified.
    Also, I recommend putting the redirect as the last line, after processing. As mentioned by another earlier, you should do all your processing, then do your output. In this case, your output is simply the redirect header.

    I ask because I'm getting the "cannot modify header information" error. Regardless of where I place that line in the file.

  • InfidelInfidel It's not Infidel, it's INNNNNFIDELRegistered User regular
    guar wrote: »
    Infidel wrote: »
    Oh god, why is your table a variable?? :lol:

    Table, aka system name. I need to pass it to identify which table is being modified.

    You'll want to rethink your database design then. :) You shouldn't be allowing arbitrary tables to be deleted from, and you shouldn't have a table for each system but simply one table for them all.
    guar wrote: »
    I ask because I'm getting the "cannot modify header information" error. Regardless of where I place that line in the file.

    Make sure you don't have a space or anything before your opening <? in the file.

    Play D&D 4e? :: Check out Orokos and upload your Character Builder sheet! :: Orokos Dice Roller
    The PhalLounge :: Chat board for Phalla discussion and Secret Santas :: PhallAX 2013
    Critical Failures IRC! :: #CriticalFailures and #mafia on irc.slashnet.org
  • guarguar Registered User regular
    I think I know what the problem is. My files are encoded as UTF-8; know a workaround that doesn't involve changing the encoding?

    ed: Nevermind, figured it out. Set notepad++ UTF-8 encoding to without BOM, which seemed to fix it.

Sign In or Register to comment.