Hello, could you help me to make the submit button work! Thank you so much!

<?php
class XooWooCommerce {

    /**
     * Edited by HTC
     */
    function show_my_schedule()
    {
        global $wpdb, $current_user, $xoouserultra;

        $user_id = get_current_user_id();

        $sql = 'SELECT `id`, `member` FROM ab_staff WHERE `wp_user_id` = "' . (int)$user_id. '"';

        $msgs = $wpdb->get_results( $sql );

        $msgs1=$msgs[0];

        $d = get_object_vars($msgs1);

        $id1= $d['id'];

        $member1 = $d['member'];

        $sql1 = "SELECT `day_index`, `start_time`, `end_time` FROM ab_staff_schedule_item WHERE `staff_id` = '$id1'";

        // echo "sql1=$sql1<br/>";

        $staffs = $wpdb->get_results( $sql1 );  

    // print_r ($staffs);


        if ( !empty( $status ) )
        {
            echo '<div id="message" class="updated fade"><p>', $status, '</p></div>';
        }
        if ( member1===0 )
        {
            echo '<p>', __( 'This function is only for our members.', 'xoousers' ), '</p>';
        }
        else
        {
            // $staff_ar = get_object_vars($staffs);

            ?>
            <form action="<?php echo "$PHP_SELF?module=schedule" ?>" method="post">

                <table class="widefat fixed" id="table-3" cellspacing="0">
                    <thead>
                    <tr>


                        <th class="manage-column" ><?php _e( 'Jour', 'xoousers' ); ?></th>
                        <th class="manage-column"><?php _e( 'De', 'xoousers' ); ?></th>
                        <th class="manage-column" ><?php _e( 'a', 'xoousers' ); ?></th>
                    </tr>
                    </thead>
                    <tbody>
                        <?php
                        foreach ( $staffs as $staff )
                        {

                            ?>
                        <tr>

                            <td><?php echo $staff->day_index; ?></td>
                            <td><input name="start_time" type="text" value="<?php echo $staff->start_time; ?>"></td>
                            <td><input name="end_time" type="text" value="<?php echo $staff->end_time; ?>"></td>

                        </tr>
                            <?php

                        }
                        ?>
                    </tbody>
                    <td>
                    <input name="" type="submit" id="update" value="Update">
                    </td>
                </table>
            </form>

            <?php    
        }
        ?>

    <?php
    }

}
$key = "woocommerce";
$this->{$key} = new XooWooCommerce();

Recommended Answers

All 9 Replies

Member Avatar for diafol

WHat do you mean "make it work"?

WHat's wrong with it?

$PHP_SELF?module=schedule

looks odd. Isn't that supposed to be $_SERVER['PHP_SELF']?module=schedule ?

You show no form handling code whatsoever, so how are we supposed to know what you want to do with the sent data?

This is using global variables - bad. Where did you get this script? I'd get another one or write your own.

Member Avatar for diafol

You still don't show your update code, so how can we help you?

Yes, I need your help. That means when I change the time in the input form then press on update button, nothing change and write into the table ab_staff_schedule_item

Please help me!

Thank you so much.

I'm using this code for wordpress.

Member Avatar for diafol

For the third time of asking, show your update code. You are sending info to the server, but we can't see what you're doing with it.

This will be where you see $_POST variables and the give-away 'UPDATE' sql statement. Some of this may be hidden away in functions or classes, but unless you show it, I can't see how we can help you. I'll respond and try to help only when you supply this info.

It's the update code

<?php 
if (isset($_POST['submit'])) {

$i = 0;
foreach ($_POST as $staffs) {
    $start = $_POST['start_time'][$i];
    $end = $_POST['end_time'][$i];

    mysql_query("INSERT INTO ab_staff_schedule_item (start_time, end_time) VALUES ('$start', '$end')");
$i++;
} 
}
?>
Member Avatar for diafol

THe foreach makes no sense. You are using $staffs as the individual array item, but you ake no use of it.

I'm afraid I don't know how your POST data looks like to advise further. ANyway - you said you had issues with UPDATING:

Now, when I click on the Update button, it don't write the data on input form into the table.

But this code is CREATING with the INSERT statement. COnfused.

So for the code you posted, do this:

if (isset($_POST['submit'])) {
    print_r($_POST);
    $i = 0;
    ... 

and post the output of the print_r here.

Hello
I think you have not added name in your input element.

 <input name="" type="submit" id="update" value="Update">

replace above with

 <input name="submit" type="submit" id="update" value="Update">

Then only your submit action will perform because you are checking

 if (isset($_POST['submit'])) {

Thank you.

I found the solution. These are the updating code:

            <?php
            if(!empty($_POST['submit'])) {
            $day_index=$staff->day_index;
            $start1 = $_POST['start_time1'];
            $end1 = $_POST['end_time1'];
            $start2 = $_POST['start_time2'];
            $end2 = $_POST['end_time2'];
            $start3 = $_POST['start_time3'];
            $end3 = $_POST['end_time3'];
            $start4 = $_POST['start_time4'];
            $end4 = $_POST['end_time4'];
            $start5 = $_POST['start_time5'];
            $end5 = $_POST['end_time5'];
            $start6 = $_POST['start_time6'];
            $end6 = $_POST['end_time6'];
            $start7 = $_POST['start_time7'];
            $end7 = $_POST['end_time7'];
            $command = "UPDATE ab_staff_schedule_item
            SET
            start_time = CASE day_index
            WHEN 1 THEN '$start1'
            WHEN 2 THEN '$start2'
            WHEN 3 THEN '$start3'
            WHEN 4 THEN '$start4'
            WHEN 5 THEN '$start5'
            WHEN 6 THEN '$start6'
            WHEN 7 THEN '$start7'
            END,
            end_time = CASE day_index
            WHEN 1 THEN '$end1'
            WHEN 2 THEN '$end2'
            WHEN 3 THEN '$end3'
            WHEN 4 THEN '$end4'
            WHEN 5 THEN '$end5'
            WHEN 6 THEN '$end6'
            WHEN 7 THEN '$end7'
            END
            WHERE `staff_id` = '$id1' AND `day_index` IN (1,2,3,4,5,6,7)";
            $result = $wpdb->get_results($command);
            echo "<p>".__( 'Updated', 'xoousers' )."</p>";    
            }
            ?>
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.