Last active
August 29, 2015 14:12
-
-
Save rakhimoni/a14b300da2e338d25a27 to your computer and use it in GitHub Desktop.
Data insert error in Titanium
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* APP.JS ---which diaplys a form | |
* want to insert values from this form. But value is not inserted in database. And show error in Ti logs | |
* | |
* Ti loggs: | |
* | |
* | |
* [ERROR] : TiHttpClient: (TiHttpClient-1) [31929,31929] HTTP Error (org.apache.http.client.HttpResponseException): Forbidden | |
[ERROR] : TiHttpClient: org.apache.http.client.HttpResponseException: Forbidden | |
[ERROR] : TiHttpClient: at ti.modules.titanium.network.TiHTTPClient$LocalResponseHandler.handleResponse(TiHTTPClient.java:275) | |
[ERROR] : TiHttpClient: at ti.modules.titanium.network.TiHTTPClient$LocalResponseHandler.handleResponse(TiHTTPClient.java:219) | |
[ERROR] : TiHttpClient: at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:657) | |
[ERROR] : TiHttpClient: at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:637) | |
[ERROR] : TiHttpClient: at ti.modules.titanium.network.TiHTTPClient$ClientRunnable.run(TiHTTPClient.java:1328) | |
[ERROR] : TiHttpClient: at java.lang.Thread.run(Thread.java:856) | |
[INFO] : ALERT: (KrollRuntimeThread) [142,32071] error | |
* | |
*/ | |
var win = Titanium.UI.createWindow({ | |
backgroundColor : 'red', | |
}); | |
// get refernce to the current window | |
var queslabel = Titanium.UI.createLabel({ | |
text : 'Question', | |
height : 50, | |
color : '#000000', | |
font : { | |
fontSize : 14 | |
}, | |
top : "10%", // vertical postion of label on the screen w.r.t screen top | |
left : "2%", // horizontal postion of label on the screen w.r.t screen left | |
width : 200 // width of the label | |
}); | |
win.add(queslabel); | |
// add label to the current window | |
var questext_field = Titanium.UI.createTextField({ | |
color : '#000000', | |
height : 50, | |
top : "10%", // vertical postion of label on the screen w.r.t screen top | |
right : "2%", // horizontal postion of label on the screen w.r.t screen left | |
width : 200, // width of the field | |
borderStyle : Titanium.UI.INPUT_BORDERSTYLE_ROUNDED | |
}); | |
win.add(questext_field); | |
// add field to the current window | |
/////////// options A //////// | |
var option_alabel = Titanium.UI.createLabel({ | |
text : 'Option A', | |
height : 50, | |
color : '#000000', | |
font : { | |
fontSize : 14 | |
}, | |
top : "20%", // vertical postion of label on the screen w.r.t screen top | |
left : "2%", // horizontal postion of label on the screen w.r.t screen left | |
width : 200 // width of the label | |
}); | |
win.add(option_alabel); | |
// add label to the current window | |
var option_atext_field = Titanium.UI.createTextField({ | |
color : '#000000', | |
height : 50, | |
top : "20%", // vertical postion of label on the screen w.r.t screen top | |
right : "2%", // horizontal postion of label on the screen w.r.t screen left | |
width : 200, // width of the field | |
borderStyle : Titanium.UI.INPUT_BORDERSTYLE_ROUNDED | |
}); | |
win.add(option_atext_field); | |
//////// end option A ////// | |
//////// option B ////// | |
var option_blabel = Titanium.UI.createLabel({ | |
text : 'Option B', | |
height : 50, | |
color : '#000000', | |
font : { | |
fontSize : 14 | |
}, | |
top : "30%", // vertical postion of label on the screen w.r.t screen top | |
left : "2%", // horizontal postion of label on the screen w.r.t screen left | |
width : 200 // width of the label | |
}); | |
win.add(option_blabel); | |
// add label to the current window | |
var option_btext_field = Titanium.UI.createTextField({ | |
color : '#000000', | |
height : 50, | |
top : "30%", // vertical postion of label on the screen w.r.t screen top | |
right : "2%", // horizontal postion of label on the screen w.r.t screen left | |
width : 200, // width of the field | |
borderStyle : Titanium.UI.INPUT_BORDERSTYLE_ROUNDED | |
}); | |
win.add(option_btext_field); | |
//////// end option B ////// | |
//////// option C ////// | |
var option_clabel = Titanium.UI.createLabel({ | |
text : 'Option C', | |
height : 50, | |
color : '#000000', | |
font : { | |
fontSize : 14 | |
}, | |
top : "40%", // vertical postion of label on the screen w.r.t screen top | |
left : "2%", // horizontal postion of label on the screen w.r.t screen left | |
width : 200 // width of the label | |
}); | |
win.add(option_clabel); | |
// add label to the current window | |
var option_ctext_field = Titanium.UI.createTextField({ | |
color : '#000000', | |
height : 50, | |
top : "40%", // vertical postion of label on the screen w.r.t screen top | |
right : "2%", // horizontal postion of label on the screen w.r.t screen left | |
width : 200, // width of the field | |
borderStyle : Titanium.UI.INPUT_BORDERSTYLE_ROUNDED | |
}); | |
win.add(option_ctext_field); | |
//////// end option C ////// | |
//////// Result ////// | |
var resultlabel = Titanium.UI.createLabel({ | |
text : 'Result', | |
height : 50, | |
color : '#000000', | |
font : { | |
fontSize : 14 | |
}, | |
top : "50%", // vertical postion of label on the screen w.r.t screen top | |
left : "2%", // horizontal postion of label on the screen w.r.t screen left | |
width : 200 // width of the label | |
}); | |
win.add(resultlabel); | |
// add label to the current window | |
var resulttext_field = Titanium.UI.createTextField({ | |
color : '#000000', | |
height : 50, | |
top : "50%", // vertical postion of label on the screen w.r.t screen top | |
right : "2%", // horizontal postion of label on the screen w.r.t screen left | |
width : 200, // width of the field | |
borderStyle : Titanium.UI.INPUT_BORDERSTYLE_ROUNDED | |
}); | |
win.add(resulttext_field); | |
//////// End of result ////// | |
var savebutton = Titanium.UI.createButton({ | |
title : 'Save', | |
top : "60%", // vertical postion of label on the screen w.r.t screen top | |
width : 200, // width of the button | |
height : 50 // width of the button | |
}); | |
win.add(savebutton); | |
savebutton.addEventListener('click', function() { | |
question = questext_field.value; | |
option_a = option_atext_field.value; | |
option_b = option_btext_field.value; | |
option_c = option_ctext_field.value; | |
result = resulttext_field.value; | |
url = "http://www.uhaat.com/quiz/question.php"; | |
client = Ti.Network.createHTTPClient({ | |
// function called when the response data is available | |
onload : function(e) { | |
Ti.API.info("Received text: " + this.responseText); | |
alert('success'); | |
}, | |
// function called when an error occurs, including a timeout | |
onerror : function(e) { | |
Ti.API.debug(e.error); | |
alert('error'); | |
}, | |
timeout : 5000 // in milliseconds | |
}); | |
var params = { | |
question: question, | |
option_atext_field: option_a, | |
option_btext_field: option_b, | |
option_ctext_field: option_c, | |
result:resulttext_field | |
}; | |
client.open("GET", url); | |
// Send the request. | |
client.send(params); | |
}); | |
win.open(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Connect to the database(host, username, password) | |
$con = mysql_connect('localhost','','');// set my credentials | |
if (!$con) | |
{ | |
echo "Failed to make connection."; | |
exit; | |
} | |
// Select the database. Enter the name of your database (not the same as the table name) | |
$db = mysql_select_db('aatuhdfg_quiz'); | |
if (!$db) | |
{ | |
echo "Failed to select db."; | |
exit; | |
} | |
$question = $_POST['question']; | |
$option_atext_field = $_POST['option_atext_field']; | |
$option_btext_field = $_POST['option_btext_field']; | |
$option_ctext_field = $_POST['option_ctext_field']; | |
$resulttext_field = $_POST['resulttext_field']; | |
$insert = "INSERT INTO question_mgmt (question,option_atext_field,option_btext_field,option_ctext_field,resulttext_field) VALUES ('" . $question . "','" . $option_atext_field . "','" . $option_btext_field . "','" . $option_ctext_field . "','" . $resulttext_field . "')"; | |
$query = mysql_query($insert); | |
if ($query) | |
{ | |
echo "Thanks for registering. You may now login."; | |
} | |
else | |
{ | |
echo "Insert failed"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment