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>