dongle2627 2014-07-05 11:04
浏览 57

获取Foreach数据

I am trying to get foreach data I am using jquery to submit the page without a refresh being required for some reason jQuery is not retrieving the foreach data, It needs to loop through each admin input field to see each data seperatly.

If it's not possible I won't use JQuery for this but thought I ask

PHP:

if(isset($_POST['admin_add']) AND is_array($_POST['admin_add'])) {
    foreach($_POST['admin_add'] as $admin_add) {
        if(strlen($admin_add) > 0) {
            // $sql=mysql_query("insert into hobbies(hobby)values('$hobby')");
        }
    }
}

die('<h3>'.$admin_add.'<h3/>');

jQuery:

$(document).ready(function () {

    var clan_url_string = window.location.search.substring(1);
    // Make a function that returns the data, then call it whenever you
    // need the current values
    function getData() {
        return {
            clan_title_edit: $('#clan_title_edit').val(),
            clan_des: $('#clan_des').val(),
            admin_add: $('#admin_add').val(),
            //remember_me: ($('#remember_me').is(':checked')) ? 1 : 0
        }
    }

    $(window).load(function(){
        $('#background_cycler').fadeIn(1500);//fade the background back in once all the images are loaded
        setInterval('cycleImages()', 4000); // run every 4s
    });


    function loading(e) {
        $('#loading_status').show();
    }

    function hide_loading(e) {
        $('#loading_status').hide();
    }

    function success_message(e) {
        $('#success_login').html("We're Just Signing You In");
    }

    function clearfields() {
        $('#login-username').val('');  //Clear the user login id field
        $('#login_password').val('');  //Clear the user login password field        
    }

    function check(e) {
        e.preventDefault();
        $.ajax({
            url: 'ajax/save_settings.php?'+clan_url_string,
            type: 'post',
            error: function () {
                //If your response from the server is a statuscode error. do this!!!'

                hide_loading(e);
                $('#status_message').html('<b>Something Has Gone Wrong</b><br> Please Try Again Later');
            },

            beforeSend: function () {
                loading(e);
            },

            data: {
                clan_title_edit: $('#clan_title_edit').val(), 
                clan_des: $('#clan_des').val(),
                admin_add: $('#admin_add').val(),
                remember_me: ($('#remember_me').is(':checked')) 
            }, // get current values

            success: function (data) {
                //if your response is a plain text. (e.g incorrect username or password)
                hide_loading(e);
                $('#status_message').hide();
                $('#status_message').fadeIn(1000).html(data);
            }
        });
    }

    // Don't repeat so much; use the same function for both handlers
    $('#login_content').keyup(function (e) {
        if (e.keyCode == 13) {
            var username = $('#login-username').val();
            check(e);
        }
    });

    $('#submit_clan_settings').click(function (e) {
        if (e.keyCode != 13) {
            check(e);
        }
    });

There's the php and jquery

Thanks

Yes its SQL injection prone, havent fix this yet and I should be using mysqli or $db->);

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 Unity接入微信SDK 无法开启摄像头
    • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
    • ¥20 cad图纸,chx-3六轴码垛机器人
    • ¥15 移动摄像头专网需要解vlan
    • ¥20 access多表提取相同字段数据并合并
    • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
    • ¥20 Java-Oj-桌布的计算
    • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
    • ¥20 有人知道这种图怎么画吗?
    • ¥15 pyqt6如何引用qrc文件加载里面的的资源