Languages

Menu
Sites
Language
Data sending to DB server from z3 phone.
It works cloud server's localhost. And if I input values in html(my laptop's web browser), DB server's database is change.
But when I tried this codes on my Z3, it didn't work...
I added internet privileges in config.xml.
Why I can't insert datas to DB server from Z3?
Save.php file is on my cloud server. Route is like /var/www/html/save.php
End of this page has link that is my project.
 
I annotated "//window.onload = function() {  //}; " but DB had no change.
 
I have to send the data that is from arduino to DB server via Z3.
 
index.html
 
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="Tizen Mobile Web Basic Template" />
<script src="js/main.js"></script>
<h1>아령하세요 운동 설정 화면</h1>
 
    <link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
<form method="post">
  <p>운동 종목 : 
  <input type="radio" name="workout" value="덤벨 컬"/>덤벨 컬
  <input type="radio" name="workout" value="레터럴 레이즈"/>레터럴 레이즈
  <!--<input type="text" name="workout"/></br>-->
  <br>
       세트 수 : <input type="text" name="sets"/></br>
  반복 수 : <input type="text" name="reps"/></br>
  중  량 : <input type="text" name="weight"/>
  </p>
 <p><input type="submit" onclick="save()"/></p>
</form>
</body>
</html>
 
main.js
 
//window.onload = function() {
    // TODO:: Do your initialization job
alert("js파일 열림");
function save() {
    /// ie5, 6은 고려하실 필요가 없습니다. 
    if (window.XMLHttpRequest) {
    // code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
  } else { // code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  } 
    xmlhttp.onreadystatechange=function() {  
            if (this.readyState==4 && this.status==200) {  
                    document.getElementById("txtHint").innerHTML=this.responseText;  
            }  
    } 
    var form = document.querySelector('form'); 
    var data = new FormData(form);  /// form 항목을 serialize 해주는 class 입니다. 
    xmlhttp.open("POST", "MY CLOUD SERVER IP/save.php", true); 
    xmlhttp.send(data);  
}
 
    // add eventListener for tizenhwkey
    document.addEventListener('tizenhwkey', function(e) {
        if (e.keyName === "back") {
            try {
                tizen.application.getCurrentApplication().exit();
            } catch (ignore) {}
        }
    });
//};
 
 
Here is project .zip
http://oneshottenkill.tistory.com/169
 
PS. php code
 

<?php
$workout = strval($_POST['workout']); //운동 종목
$sets = intval($_POST['sets']);       //세트 수
$reps = intval($_POST['reps']);       //반복 수
$weight = intval($_POST['weight']);   //중량

$con = mysqli_connect('localhost','root','PASSWORD','dumbbell');
if (!$con) {
    die('Could not connect: ' . mysqli_error($con));
}

mysqli_select_db($con,"dumbbell");

$sql = "UPDATE user
SET Workout='$workout', Sets = $sets, Reps = $reps, Weight=$weight
WHERE ID = 2;";

$result = mysqli_query($con,$sql);

if (mysqli_query($con, $sql)) {
    echo "운동 설정이 완료되었습니다.";
} else {
    echo "Error: " . $sql . "<br>" . mysqli_error($con);
}

mysqli_close($con);
?>

 

second PS.  I added action tag like this <form action="http://115.68.232.116/save.php" method="post">

and then web browser was opened... I loss my datas.

 ----------▶ 

 

 

Edited by: 명훈 심 on 22 Feb, 2018

Responses

1 Replies
명훈 심

I solved.

1. I annotated "<!--<script src="save.js"></script>-->"

2. I deleted save.js "<p><input type="submit"/></p>", I mean I didn't use main.js .

3. I added <access origin="*" subdomains="true"/> in Source of config.xml file.