簡體   English   中英

在TideSDK中將表單數據插入沒有PHP的sqlite3查詢中

[英]Insert form data into sqlite3 query without php in TideSDK

我一直在搜索幾個小時,可能只是我是一個新手,但是我很難弄清楚如何在sqlite3查詢中動態輸入文本,因為它們不接受變量(或者我相信)。

這是我正在嘗試做的事情:

用戶當前可以在我的TideSDK應用程序中查看食譜-食譜的內容是從名為recipes.db的文件生成的

此代碼將一個單獨的配方加載到主屏幕中:

function doMainChange70() {
    var db = Ti.Database.openFile(Ti.Filesystem.getFile(Ti.Filesystem.getApplicationDataDirectory(), 'recipes.db'));
    var rows = db.execute("SELECT * FROM recipe WHERE number = '70'");
    while (rows.isValidRow()) {
    $('#foodFoto').empty();
    $('#titleArea').empty();
    $('#servings').empty();
    $('#tagline').empty();
    $('#ingredients').empty();
    $('#directions').empty();
    $('#nutrition').empty();
    $('#foodFoto').append("<img src='foodPics/r" + rows.fieldByName('number') + ".jpg' />");
    $('#titleArea').append("<p>" + rows.fieldByName('title') + '</p>');
    $('#servings').append("<p>" + rows.fieldByName('servings') + '</p>');
    $('#tagline').append("<p>" + rows.fieldByName('tagline') + '</p>');
    //$('#ingredients').
    $('#directions').append("<p>" + rows.fieldByName('directions') + '</p>');
    $('#nutrition').append("<p>" + rows.fieldByName('nutrition') + '</p>');
    $('#editBtn').remove();
    $('#mainBtns').append("<a href='#' id='editBtn'" + 'onclick=' + 'editRecipe' + rows.fieldByName('number') + "()><img src='RecipeButton5.png' /></a>");
    rows.next();
    rows.close();
    db.close();
    return false;
}

}

我現在希望用戶能夠編輯配方。 當前,當單擊編輯按鈕時,配方的所有字段都將更改為輸入標簽,用戶可以編輯:

function editRecipe70() {
$('#editBtn').removeAttr('onclick');
var db = Ti.Database.openFile(Ti.Filesystem.getFile(Ti.Filesystem.getApplicationDataDirectory(), 'recipes.db'));
var rows = db.execute("SELECT * FROM recipe WHERE number = '70'");
while (rows.isValidRow()) {
$('#editBtn').html("<img src='saveRecipeButton.png' />");
$('#formContainer').empty();
$('#formContainer').append("<form id='sendEdit'><textarea type='text' name='title' id='title'>" + rows.fieldByName('title') + "</textarea><br>" + "<textarea type='text' name='servings'>" + rows.fieldByName('servings') + "</textarea><br>" + "<textarea type='text' name='tagline'>" + rows.fieldByName('tagline') + "</textarea><br>" + "<textarea type='text' name='directions'>" + rows.fieldByName('directions') + "</textarea><br>" + "<textarea type='text' name='nutrition'>" + rows.fieldByName('nutrition') + "</textarea><br>" + "<input type='submit'></form>");

}

我的問題是,在這一點上,我無法找到一種方法來捕獲用戶在輸入字段(或更准確地說是文本區域)中放置的內容,並將其放入sqlite3查詢字符串中。

我可以用以下方式在js中查詢數據庫:

UPDATE recipeTable SET title='best recipe ever' WHERE number='70';

但是沒有這樣的東西(這就是我所需要的):

UPDATE recipeTable SET title = '[formValueForTitle]' WHERE number = '70';

希望我有道理,對不起,這是我的第一個問題。 我在網站上看了很多帖子,立即的解決方案似乎是使用php預處理表單值,但是我已經閱讀了TideSDK中的php模塊,目前不支持sqlite3,並且無法將已處理的代碼返回index.html以在js中運行。

長期以來,我想找出一種讓用戶編輯配方的方法,但我完全陷入了困境。 任何方向將不勝感激!

謝謝

這是我的方法:

 var inputfromform = 'I got this back from the form';
  var number = 7;
  db = Ti.Database.open(dbname); // or openFile etc
  db.execute("BEGIN IMMEDIATE TRANSACTION;");
  db.execute("UPDATE recipeTable SET title = ? WHERE number = ?;", inputfromform, number);
  db.execute("COMMIT TRANSACTION;");
  db.close();

希望這可以幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM