Postingan lainnya
Insert database untuk phonegap
saya mau tanya dong . Saya running insert database saya berhasil tapi pada saat liat dimysqlnya datanya kosong kenapa yah?
<!DOCTYPE html>
<!--
Copyright (c) 2012-2016 Adobe Systems Incorporated. All rights reserved.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="msapplication-tap-highlight" content="no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width" />
<!-- This is a wide open CSP declaration. To lock this down for production, see below. -->
<meta http-equiv="Content-Security-Policy" content="default-src * 'unsafe-inline'; style-src 'self' 'unsafe-inline'; media-src *" />
<!-- Good default declaration:
* gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication
* https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly
* Disables use of eval() and inline scripts in order to mitigate risk of XSS vulnerabilities. To change this:
* Enable inline JS: add 'unsafe-inline' to default-src
* Enable eval(): add 'unsafe-eval' to default-src
* Create your own at http://cspisawesome.com
-->
<!-- <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: 'unsafe-inline' https://ssl.gstatic.com; style-src 'self' 'unsafe-inline'; media-src *" /> -->
<link rel="stylesheet" type="text/css" href="css/index.css" />
<link rel="stylesheet" type ="text/css" href="css/modal.css">
<title>Do My Day</title>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript">
function onLoad()
{
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady()
{
document.getElementById("hasil").innerHTML = "Device is Ready" ;
}
/* Fungsi mencegah input selain number(angka)*/
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
$("#button").click(function(){
var username=$("username").val();
var PIN=$("PIN").val();
var email=$("email").val();
var dataString="username="+username+"&PIN="+PIN+"&email="+email+"&button=";
if($.trim(username).length>0 & $.trim(PIN).length>0 & $.trim(email).length>0)
{
$.ajax({
type: "jsonp",
url: "insert.php",
data: dataString,
crossDomain: true,
cache: false,
beforeSend: function(){ $("#button").val('Connecting...');},
success: function(data){
if(data=="success")
{
alert("Thank you for Registering with us! you can login now");
}
else if(data="exist")
{
alert("Hey! You alreay has account! you can login with us");
}
else if(data="failed")
{
alert("Something Went wrong");
}
}
});
}return false;
});
</script>
</head>
<body onload = "document.getElementById('id01').style.display='block', onLoad">
<!-- contaier modal -->
<div class="w3-container">
<div id="id01" class="w3-modal">
<div class="w3-modal-content w3-card-8 w3-animate-zoom" style="max-width:300px">
<!-- judul form -->
<div class="w3-margin-top hs"><br>
<h3>Create Your Account</h3>
<h5>Fill in the bellow for secure your application</h5>
</div>
<!-- Form Create Account -->
<form class="w3-container" enctype="multipart/form-data" name ="create_user" action="http:localhost/insert.php" method="get">
<div class="w3-section">
<!-- Field userame -->
<label class = "label">Username</label>
<input class="w3-input w3-border w3-margin-bottom" type="text" placeholder="Enter Username" id="username" name ="username" required><br>
<!--Field Email-->
<label class = "label">Email</label>
<input class="w3-input1 w3-border w3-margin-bottom" type="email" placeholder="Enter Email" id="email" name = "email" required><br>
<!-- Field PIN -->
<label class = "label">PIN</label>
<input class="w3-input2 w3-border" type="password" type ="number" placeholder="Enter PIN" id="PIN" name="PIN" required maxlength = "6" onkeypress="return isNumberKey(event)">
<label><font color = "red" class = "syarat">*Must 6 Digit Numbers</font></label><br><br>
<!-- Tombol submit -->
<div class = "kanan">
<input type="image" name="button" src="img/03btnnxt.PNG" id="button"> <!-- <--untuk mengirim isi form ke file -->
</div>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
<?php
header('Content-type: application/json');
header('Access-Control-Allow-Origin: *');
$server = "localhost";
$database = "dmd";
$username = "root";
$password = "";
$con = mysql_connect($server, $username, $password);
// if($con) { //echo "Connected to database!"; }
// else { //echo "Could not connect!"; }
mysql_select_db($database, $con);
$topost = file_get_contents('php://input');
$thedata = json_decode($topost, true);
$username = $thedata['username'];
$PIN = $thedata['PIN'];
$email = $thedata['email'];;
$sql = "INSERT INTO registrasi (username, PIN, email) ";
$sql .= "VALUES ('$username', '$PIN', '$email')" or die(mysql_error());
if (!mysql_query($sql, $con)) {
die('Error: ' . mysql_error());
$response_array['status'] = 'error';
echo json_encode($response_array);
}
else {
echo json_encode(array('status' => 'success','message'=> 'No problem'));
$response_array['status'] = 'success';
echo json_encode($response_array);
}
mysql_close($con);
?>
tag -phonegapp-
0
Belum ada Jawaban. Jadi yang pertama Jawaban
Login untuk ikut Jawaban