Script Critique with added question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
CoolAsCarlito
Forum Contributor
Posts: 192
Joined: Sat May 31, 2008 3:27 pm
Contact:

Script Critique with added question

Post by CoolAsCarlito »

Just seeing how the coding blocks look as well as figure out on option 1 after the form submits it should be loading the file again but on option 0. Anyone understand why?

Code: Select all

<?php 

if (isset($_REQUEST['option'])) {
    switch ($_REQUEST['option']) {
    case 0:
?>
    <h1 class="backstage">Division Management</h1><br />
    <h2 class=backstage>Divisions :: <a href="#" onclick="ajaxpage('backstage_libs/division.php?option=1', 'content'); return false;">Add New</a></h2><br />
    <?php
    $query = "SELECT * FROM efed_list_divisions";
    $result = mysql_query ( $query ); 
    $rows = mysql_num_rows($result);
    if ($rows > 0)  {
        print '<table width="100%" class="table1">
               <tr class="rowheading">
               <td>&nbsp;</td>
               <td>Name</td>
               </tr>';
               $i = 0;
               while ( $row = mysql_fetch_array ( $result, MYSQL_ASSOC ) ) 
               {
                    $sClass = 'row2';
                    if ($i++ % 2) $sClass = 'row1';
                    printf ( "<tr class=\"%s\">", $sClass );
                    print "<td valign=\"top\" align=center width=35><a href=\"#\" onclick=\"ajaxpage('backstage_libs/division.php?option=2&id=$row[id].', 'content'); return false;\">Edit</a></td>";
                    printf ( "<td valign=\"top\">%s</td>", $row ['name'] );
                    echo '</tr>';
               }
echo '</table><br>';
} else {
echo '<span>There are no divisions.</span><br /><br />';
}
returnmain();
footercode();
break;
case 1:
require_once('../backstagefunctions.php');
?>
            <h1 class="backstage">Division Management</h1><br />
            <h2 class="backstage">Add New Division</h2><br />
            <form name="divisions" method="post">
                <input type="hidden" name="action" value="division" />
                <table width="100%" class="table2">
                    <tr>
                        <td width="120" class="rowheading" valign="center">Division Name:</td><td class="row3"><input type="text" name="name" class="fieldtext490"></td>
                    </tr>
                </table><br />
                <input type="hidden" name="newadded" value="true">
                <input type="submit" value="Save Division" class="button"></form><br />
                <form method="post"><input type="submit" value="Return to Division List" class="button200" name="return">
            </form><br />
            <?php
            returnmain();
        break;
case 2:
require_once('../backstagefunctions.php');
require_once('../backstageconfig.php');
$id = $_GET['id']; 
$query = mysql_query("SELECT * FROM `efed_list_divisions` WHERE `id` = '" . $id . "'");
$row = mysql_fetch_array($query);
?>
            <h1 class="backstage">Division Management</h1><br />
            <h2 class="backstage">Edit Division</h2><br />
            <form name="editdivision" method="post">
<input type="hidden" name="action" value="division" />
                <table width="100%" class="table2">
                    <tr>
                        <td width="120" class="rowheading" valign="center">Division:</td><td class="row3"><input type="text" name="name" class="fieldtext490" value="<?=$row['name'];?>"></td>
                    </tr>
                </table><br />
                <center>
<input type="checkbox" name="deletename"><span class="table1heading">Delete Division?</span><br /><br />
                <input type="hidden" name="oldname" value="<?php echo $row['name']; ?>">
                <input type="hidden" value="true" name="editted" />
<input type="submit" value="Edit Division" class="button"><br /><br />
                <input type="button" value="Return to Divisions List" class="button200"><br /><br />
            </form>
<?php
returnmain();
break;
}
}

function division() {
    if ((!empty($_POST['newadded']))) {
    $name = mysql_real_escape_string($_POST['name']);
    $query = "INSERT INTO `efed_list_divisions` (name) VALUES ('".$name."')";
    mysql_query($query);
}

    if ((!empty($_POST['editted']))) { 
    $oldname = mysql_real_escape_string($_POST['oldname']); 
    $query = "UPDATE `efed_list_divisions` SET `name` = '$name' WHERE `name` = '$oldname'";   
    mysql_query($query);
    
        if (isset($_POST['deletename'])){
        $query = "DELETE FROM `efed_list_divisions` WHERE `name` =  '".$name."' LIMIT 1"; 
        mysql_query($query);
        }
    }
}
?>
CoolAsCarlito
Forum Contributor
Posts: 192
Joined: Sat May 31, 2008 3:27 pm
Contact:

Re: Script Critique with added question

Post by CoolAsCarlito »

Any ideas or suggestions on why its giving me a white screen afterwards?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Script Critique with added question

Post by Christopher »

I'm not exactly clear what your question is, but your forms should have an action and you need a hidden field for the option param:

Code: Select all

          <form action="backstage_libs/division.php" name="divisions" method="post">
                <input type="hidden" name="option" value="1" />
(#10850)
Post Reply