Skip to content

Instantly share code, notes, and snippets.

@csemrm
Forked from rakhimoni/app.js
Created December 28, 2014 09:20
Show Gist options
  • Save csemrm/fafb1dbb7076d17b2408 to your computer and use it in GitHub Desktop.
Save csemrm/fafb1dbb7076d17b2408 to your computer and use it in GitHub Desktop.
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.bcic.gov.bd/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);
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.setRequestHeader('Content-Type', 'application/json');
client.open("POST", url);
// Send the request.
client.send(JSON.stringify(params));
});
win.open();
<?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