Hello,

I have this code and I try to print group_level before I record it and it doesn't appears:

invoice_edit.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" />
<title>Squprime</title>

<!-- CSS -->
<link href="style/css/transdmin.css" rel="stylesheet" type="text/css" media="screen" />
<!--[if IE 6]><link rel="stylesheet" type="text/css" media="screen" href="style/css/ie6.css" /><![endif]-->
<!--[if IE 7]><link rel="stylesheet" type="text/css" media="screen" href="style/css/ie7.css" /><![endif]-->

<!-- JavaScripts-->
<script type="text/javascript" src="style/js/jquery.js"></script>
<script type="text/javascript" src="style/js/jNice.js"></script>
</head>

<body>
    <div id="wrapper">
        <!-- h1 tag stays for the logo, you can use the a tag for linking the index page -->
        <h1><a href="#"><span>Squprime</span></a></h1>
        <img src="images/logo2.png" height="70px" style="margin: -45px 0 0 -180px; position: absolute;"><br><!--<img src="images/admin.png" height="60px" style="margin: -20px 0 0 430px">--><br><br>
        <!-- You can name the links with lowercase, they will be transformed to uppercase by CSS, we prefered to name them with uppercase to have the same effect with disabled stylesheet -->

        <?php include('top_nav.php'); ?>

        <!-- // #end mainNav -->

        <div id="containerHolder">
            <div id="container">
                <div id="sidebar">

                    <?php include("admin_nav.php"); ?>

                    <!-- // .sideNav -->
                </div>    
                <!-- // #sidebar -->

                <div style="margin: -15px 0 0 230px; width: 700px; position: absolute;">
                <!-- h2 stays for breadcrumbs -->
                <h2><a href="#">Dashboard</a> &raquo; <a href="#" class="active">Invoice</a></h2>
                </div>


                <!-- Insert New -->

<div id="menu">   
      <center>  

      </center>
      <p>&nbsp;</p>

  <p>&nbsp;</p><center>
      <p>

<?php

    include('includes/koneksi.php');

    $date = isset($_POST['date']) ? $_POST['date'] : '';  
    $confirmation = isset($_POST['confirmation']) ? $_POST['confirmation'] : '';     
    $group_date = isset($_POST['group_date']) ? $_POST['group_date'] : ''; 
    $group_name = isset($_POST['group_name']) ? $_POST['group_name'] : ''; 
    $group_package = isset($_POST['group_package']) ? $_POST['group_package'] : '';
    $group_level = isset($_POST['group_level']) ? $_POST['group_level'] : '';
    $group_teacher = isset($_POST['group_teacher']) ? $_POST['group_teacher'] : '';
    $group_payment = isset($_POST['group_payment']) ? $_POST['group_payment'] : ''; 

    echo $group_level;

    //Simpan berita 
    if (isset($_POST['ok'])){       

        if (empty($_GET['group_id']))
            {
            $sqlstr = "INSERT INTO `invoice`(group_date, group_name, group_package, group_level, group_teacher, group_payment) VALUES('".$group_date."','".$group_name."','".$group_package."','".$group_level."','".$group_teacher."','".$group_payment."')";          
            }
        else
            {           
            $sqlstr = "UPDATE `group` SET group_date='".$group_date."', group_name='".$group_name."', group_package='".$group_package."', group_level='".$group_level."', group_teacher='".$group_teacher."' WHERE group_id='".$_GET['group_id']."'";           
            }       

        $result = mysql_query($sqlstr) or die(mysql_error());

        //Jika mode edit, maka tidak akan dikirimkan konfirmasi kepada subscriber
        //if (empty($_REQUEST['id']))   kirimEmail($idKategori, $judul, $news);
        $confirmation = ($result) ? "Data has been saved." : "Fail to save data.";  
    }

    //Load berita
    if (!empty($_GET['group_id'])){

        $result = mysql_query("SELECT * FROM `group` WHERE group_id =".$_GET['group_id']) or die(mysql_error());
        $data = mysql_fetch_array($result);     
        $group_id = $data['group_id'];
        $group_date = $data['group_date'];
        $group_name = $data['group_name'];
        $group_package = $data['group_package'];
        $group_level = $data['group_level'];
        $group_teacher = $data['group_teacher'];
        $group_payment = $data['group_payment'];

    }else {
        // set all empty for new info
        $group_id = "";
        $group_date = "";
        $group_name = "";
        $group_package = "";
        $group_level = "";
        $group_teacher = "";
        $group_payment = "";

    }

    ?>

    <div align="center">
        <div style="width:800px;text-align:left;">
        <?php echo '<br><br>'; ?>
        <?php echo $confirmation;?>      
        <form method="post" action="<?php echo $_SERVER['PHP_SELF'].'?group_id='. $group_id;?>">
            <!-- <input type="hidden" name="id" value="<?php// echo $id; ?>"/>--><br><br><br><br><br><br>
            <table>
                <tr>
                    <td>Group Date</td>   
                    <td><input type="text" size="15px" name="group_date" value="<?php echo $group_date; ?>"></td>
                </tr>
                <tr>
                    <td>Group Name <font color="red"></font></td>               
                    <td><input type="text" size="30px" name="group_name" value="<?php echo $group_name; ?>"></td>
                </tr>
                <tr>
                    <td valign="top">Package</td>         
                    <td><?php
                    $row = mysql_query("SELECT * FROM `package`") or die(mysql_error());
                    echo '<select name="group_package">';
                    while($data = mysql_fetch_array($row)){
                        echo '<option value="'.$data['package'].'"';
                        if($group_package == $data['package']){
                        echo 'selected="selected"';}
                        echo '>'.$data['package'].'</option>';
                        }
                    echo '</select>';    
                    ?></td>
                </tr>
                <tr>
                    <td>Level</td>
                    <td><?php
                    $row2 = mysql_query("SELECT * FROM `level`") or die(mysql_error());
                    echo '<select name="group_level">';
                    while($data2 = mysql_fetch_array($row2)){
                        echo '<option value="'.$data2['level
                        _name'].'"';
                        if($group_level == $data2['level_name']){
                        echo 'selected="selected"';}
                        echo '>'.$data2['level_name'].'</option>';
                        }                       
                    echo '</select>';    
                    ?></td>
                </tr>
                <tr>
                    <td>Teacher</td>
                    <td><input type="text" size="30px" name="group_teacher" value="<?php echo $group_teacher; ?>">
                    </td>
                </tr>
                <tr>
                    <td>Payment</td>
                    <td><?php
                    $row2 = mysql_query("SELECT * FROM `group`") or die(mysql_error());
                    echo '<select name="group_payment">';
                    echo '<option value="PAID"';
                    if($group_payment == "PAID"){
                    echo 'selected="selected"';}
                    echo '>PAID</option>';
                    echo '<option value="UNPAID"';                   
                    if($group_payment == "UNPAID"){
                    echo 'selected="selected"';}
                    echo '>UNPAID</option>';                 
                    echo '</select>';    
                    ?></td>
                </tr>

                <tr>             
                    <td></td>
                    <td><br><input type="submit" name="ok" value="Save" class="abutton"/></td>
                </tr>
            </table>
        </form>
        </div>
    </div>
</div> 


                <!-- End Insert -->  

                <div class="clear"></div>
            </div>
            <!-- // #container -->
        </div>   
        <!-- // #containerHolder -->

        <p id="footer">Feel free to use and customize it. <a href="http://www.perspectived.com">Credit is appreciated.</a></p>
    </div>
    <!-- // #wrapper -->
</body>
</html>

Recommended Answers

All 5 Replies

where is the "group_level" in your form?

this will always be empty

 $group_level = isset($_POST['group_level']) ? $_POST['group_level'] : '';

because it will never evaluates to true and you've sets expressions setting everything with empty values by default.

 // set all empty for new info
    $group_id = "";
    $group_date = "";
    $group_name = "";
    $group_package = "";
    $group_level = "";
    $group_teacher = "";
    $group_payment = "";

you add something like this in your form

<input type="text" name="group_level">

This is group_level:

invoice_edit.php

<tr>
    <td>Level</td>
    <td><?php
        $row2 = mysql_query("SELECT * FROM `level`") or die(mysql_error());
        echo '<select name="group_level">';
              while($data2 = mysql_fetch_array($row2)){
        echo '<option value="'.$data2['level
_name'].'"';
        if($group_level == $data2['level_name']){
            echo 'selected="selected"';}
            echo '>'.$data2['level_name'].'</option>';
        }
        echo '</select>';
    ?></td>
</tr>

It's a combo box, not a textbox.

You haven't closed your while loop here.

I did close it. It's on line 12. Bracket in line 9 already closed on line 10.

Oh yes sorry my bad, didn't see it.

Maybe try indenting your code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.