0

I have another question. Why I cant get into this 'isset' $_POST["zapisz"] in this code ? What is wrong ?

    function ow_display_user() {
    ?>
    <pre style="text-align: left;">
    <?php if ($_SERVER['REQUEST_METHOD'] === 'POST') var_dump($_POST); ?>
    </pre>
    <? 
    wp_enqueue_script('jquery-ui-datepicker');
    wp_enqueue_style('jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css');

    global $wpdb;
    $results = $wpdb->get_results ("SELECT adres FROM wp_ow_adres;");
    ?>
<form name="one" method="post" action="">
    <table>
        <tbody>
            <tr>
                <th><label for="Adres">Adres zamieszkania</label></th>
                <td><select id="adres" name="adres">
                        <option value="">Wybierz swój adres</option>
                        <?php 
                        foreach ( $results as $result ) {
            echo '<option>'.$result->adres.'</option>';
        }
        ?>
                </select></td>
            </tr>
            <tr>
                <td><input type="submit" name="ok" value="Wybierz" />

                <td>

            </tr>
        </tbody>
    </table>
</form>
<?php 
$adres = $_POST["adres"];

if (isset($_POST['ok'])){
    $spr_liczbe_wodo = $wpdb->get_var("select liczba_wodomierzy from wp_ow_adres where adres='$adres'");

    if ($spr_liczbe_wodo == 4) {
    ?>
        <form name="two" method="post" action="http://localhost.local/">
        <table>
        <tbody>
        <tr>
        <td>Adres zamieszkania:</td>
        <td><?php $adres?></td>
        </tr>
        <tr>
        <td>Woda ciepła (kuchnia):</td>
        <td><input type="text" id="woda_ciepla_kuchnia" name="woda" /></td>
        </tr>
        <tr>
        <td></td>
        <td><input type="submit" id="zapisz" name="zapisz" value="Zapisz" /></td>
        </tr>
        </tbody>
        </table>
        </form>
    <?

        if(isset($_POST['zapisz']))
        {
        $woda_ciepla_kuchnia=1;
        $data_odczytu = '0013-00-00 22:00:00';

                $data = array(
                'id' => '',
                'adres' => 'dasd',
                'data_odczytu' => $data_odczytu,
                'woda_ciepla_kuchnia' => 1,

                );

                $wpdb->insert(wp_ow_odczyty, (array)$data);

                            }
                            }

    }

}
  • check you code, their is a semicolon in it after second if close.this should not be their. – Ravinder Kumar Dec 30 '13 at 11:19
  • 1
    I change $wpdb->insert(wp_ow_odczyty, (array)$data); } }; to $wpdb->insert(wp_ow_odczyty, (array)$data); } } correct ? – Przemysław Suszek Dec 30 '13 at 11:31
  • yes this syntax is correct – Ravinder Kumar Dec 30 '13 at 11:36
  • Still the same issue. Any idea ? – Przemysław Suszek Dec 30 '13 at 11:39
  • 2
    Where are you setting ok and 'adres' in form? You are checking isset($_POST['ok']), $_POST["adres"], are you sure this is the proper code? Also, there is no need to use that much echo statements to print the form code, just close php tag after if ($spr_liczbe_wodo == 4) { ?> and start php tag after </form> <?php and write simple html in between – Kumar Dec 30 '13 at 11:55
2

After the second form </form> make a small change close the first two if's, and remove the two } from end of function

     </form><?php
     }
    }
    if(isset($_POST['zapisz'])) {
    $woda_ciepla_kuchnia=1;
    $data_odczytu = '0013-00-00 22:00:00';

    $data = array(
      'id' => '',
      'adres' => 'dasd',
      'data_odczytu' => $data_odczytu,
      'woda_ciepla_kuchnia' => 1,
    );
    $wpdb->insert(wp_ow_odczyty, (array)$data);
   }
 }
  • why do you use (array)$data if you are already have variable with type array ? – Brotheryura Dec 1 '14 at 21:04
  • It's just I didn't edited the rest of code in question, (array) it is not really required :) – Kumar Dec 2 '14 at 8:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.