dongzheng4556 2016-10-12 13:08
浏览 23

mysql在表中输入9个条目后返回不同的值

I have a mobile app that interacts with php instructions sitting on a linux server (php, mysql). A user is able to submit an item (in the app) by selecting a category, writing description, uploading a picture, price information and it all works fine as long as my 'category' table entries are 9 or less. As soon as I enter 10th entry into the table and select that category in the app, the submitted value defaults to 1 or 2 in the submission 'items' table. The 'category' table has just two columns: id and name

I am fairly new to programming but Here is the pc of code I think is responsible:

 function getCatagorysucessSel(result)
 {
    //window.localStorage.setItem("get_catagory",result);
    //placecatgrySelpage();     
    $('#select_choice_myitem').empty();     
    if(result.hasOwnProperty('categoryData'))
    {
        $('#select_choice_myitem').append(new Option(_('category'), '-1'));

        for(var i=0;i<result.categoryData.length;i++)
        {            
            $('#select_choice_myitem').append(new Option(_(result.categoryData[i].name), result.categoryData[i].id));           
        }
    }
    else
    {
        alert("No category available");
    }
    $('#select_choice_myitem').find('option').each(function()
    {       
         if($(this).val()==-1)
         {
             $(this).attr('selected','selected');
         }
         else
         {
            $(this).removeAttr('selected','selected');
         }
    }); 
    //$("#select_choice_myitem [value='-1']").attr("selected","selected");      
    //$("#select_choice_myitem").val("-1").attr("selected", "selected");

    var activePage = $.mobile.activePage.attr("id");

    if (activePage == 'main_screen') 
    {
        //resetting submit item input fields
        window.localStorage.setItem("my_item_image",'');    
        $('#picture').attr('src','./themes/images/camera-icon.png')
        photo_imgeuri='./themes/images/camera-icon.png';
        $('.setting-form .ui-input-text').css({"background-color":"#fff"});
        $('.select-style').css({"background-color":"#fff"});
        $('#select_choice_myitem').trigger('create');           
        $('#textinput-hide_price').val('');             
        $('#textinput_hide_desc').val(''); 
        document.getElementById('submit_Sellpage').onclick = function() { saveItemSubmit(''); };
        $('#submit_Sellpage').css({"background-color":"#0099cb"});
        $('#submit_Sellpage').html(_('submit')); 

        pageNavigation('sellingPge');       
    }
    else
    {
        changeItemPage();
    }   
    $('#select_choice_myitem').selectmenu('refresh');
 }

 /*function placecatgrySelpage()
 {      
        $('#select_choice_myitem').empty();
            //$('#yourSelectBoxId').append(new Option('Select a catagory', 'null'));
            //var rresulta=window.localStorage.getItem("get_catagory");
            //console.log(rresulta);    
            //rresulta=JSON.parse(rresulta);    

}*/

function getCatagorySellPage()
{     
    if (document.getElementById('picture').value == null) {
        $('#textonImage').show();
    }
    //$('#textonImage2').show();
    //photo_imgeuri='';
    //$('#picture')[0].src = '#';
      //placecatgrySelpage();
      $.ajax({
                    type: "GET",
                    url:base_url+'services/getcategorylist.php',
                    contentType: "application/json",
                    dataType: "json",
                    //data:JSON.stringify(login_json),
                    beforeSend:function(xhr){
                            showPageLoading();
                            xhr.setRequestHeader('Authorization', make_base_auth()); 
                           //ActivityIndicator.show('Loading dictionary ....Please wait!');
                    },
                    complete:function(){
                        hidePageLoading();
                        //ActivityIndicator.hide();
                    },
                    success: getCatagorysucessSel,
                    error: error
                }); 
}

Here is php code residing on the server:

$uid = userExists(isBlank('User id', $data->{"uid"}));
$sessionID = userSessionExists(isBlank('sessionID', $data->{"sessionID"}), $uid);
$cid = isBlank('Category id', $data->{"categoryid"});
$desc = isBlank('Description', $data->{"description"});
$price = isBlank('Price', $data->{"price"});
$countdown = isBlank('Countdown', $data->{"countdown"});
$picture = isBlank('Item picture', $data->{"picture"});
$lat = isBlank('Latitude', $data->{"latitude"});
$long = isBlank('Longitude', $data->{"longitude"});
$responseData = array();

// If itemid is not set, create new item and add to DB
if($data->{"itemid"} == '') {
    $insertQuery = sprintf("INSERT INTO items (itemid, cid, uid, description, price, countdown, picture, latitude, longitude, created) VALUES (NULL, %d, %d, '%s', '%f', '%s', '', '%s', '%s', '%s')", $cid, $uid, $desc, $price, $countdown, $lat, $long, time());
    mysql_query($insertQuery);
    $itemid = mysql_insert_id();

    if ($itemid != '') {
        $name = $itemid.'.jpg';
        file_put_contents("../files/itemspic/$name", base64_decode($picture));
        $picture = 'files/itemspic/'.$name;
        mysql_query("UPDATE items SET picture = '" . $picture . "' WHERE itemid = " .$itemid);
      
            $responseData['responseCode'] = '200';
        $responseData['responseStatus'] = 'success';
        $responseData['responseData'] = 'Item has been saved.';
    } else {
        $responseData['responseCode'] = '200';
        $responseData['responseStatus'] = 'error';
        $responseData['responseData'] = 'Unable to save item.';
    }
}

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?