Jump to content

ersaurabh101

New Members
  • Posts

    7
  • Joined

  • Last visited

ersaurabh101's Achievements

Member

Member (2/5)

0

Reputation

  1. I have only 1 record ( this is - username,password saved in my table) I need to select the username and count the no. of rows but both of the things not working, copying my code below SELECT STATEMENT: returning me [object][object] var selectStatement = "select username FROM loggedinuser"; var result; function getusername() { db.transaction(function (tx) { tx.executeSql(selectStatement,[],querySuccess); }); function querySuccess(tx, results) { for(var i=0; i<results.rows.length; i++) { var row = results.rows.item; result = { id: row['username']}; alert(result); } } } COUNT STATEMENT: below record is giving me result "1" at alert(len); var countStatement = "select COUNT(*) from loggedinuser"; var db = openDatabase("AddressBook", "1.0", "Address Book", 200000); // Open SQLite Database var user,password; function countRecord(tx) { db.transaction(function (tx) { tx.executeSql('SELECT count(*) FROM loggedinuser', [], querySuccess, errorCB); }); } function querySuccess(tx, results) { var len = results.rows.length; alert(len); } function errorCB(err) { alert("Error processing SQL: "+err.code); } countRecord(); Please help..
  2. Hii, For local sqlite storage i am following this tutorial - https://tejasrpatel.wordpress.com/2011/12/29/create-sqlite-off-line-database-and-insertupdatedeletedrop-operations-in-sqlite-using-jquery-html5-inputs/ I am using these commands to create a table in my login.html page - var createStatement = "CREATE TABLE IF NOT EXISTS userdetails (username TEXT, password TEXT, company TEXT)"; var db = openDatabase("QuickTask", "1.0", "Quick Task", 200000); // Open SQLite Database function initDatabase() // Function Call When Page is ready. { try { if (!window.openDatabase) // Check browser is supported SQLite or not. { alert('Databases are not supported in this browser.'); } else { createTable(); // If supported then call Function for create table in SQLite } } catch (e) { if (e == 2) { // Version number mismatch. console.log("Invalid database version."); } else { console.log("Unknown error " + e + "."); } return; } } function createTable() // Function for Create Table in SQLite. { db.transaction(function (tx) { tx.executeSql(createStatement, [], showRecords, onError); }); } After succesful login i am directing to welcome.html window.location.href = "welcome.html"; How do i access my tables on this page ? In console i am not finding any tables. I am trying to make an app [will make apk using phonegap] and stuck at the very beginning..Please help / Guide
  3. ohh, it should be ORDER BY RAND() , thanks worked , how to switch on php error reporting ?
  4. Hey, How you been, I was trying to work with json data in php and mysql using ajax Something strange is happening, when i comment the below line - // $row=mysqli_fetch_array($result,MYSQLI_ASSOC); <?php session_start(); $message=array(); include('database.php'); $sql="SELECT * from ratings ORDER BYRAND() LIMIT 1"; $result = mysqli_query($conn,$sql); $row=mysqli_fetch_array($result,MYSQLI_ASSOC); //$message["image"]=$row['image']; $message["message"]='hello'; //$message["message2"]='hello2'; header('content-type: application/json'); echo json_encode($message); I get the message in my console.log using ajax but when i uncomment this $row = mysqli_fetch_array.... i get nothing in my console log what is wrong in here ? I am on xampp 3.2.2 incase and there is no db error, also pasting my databse.php code just incase you wish to see <?php $DBServer = 'localhost'; $DBUser = 'root'; $DBPass = ''; $DBName = 'starrating'; $conn = new mysqli($DBServer,$DBUser,$DBPass,$DBName); if($conn->connect_error){ // echo $conn->connect_error; die('Connect Error: ' . $mysqli->connect_error); } function cleanup($data){ return mysql_real_escape_string(trim(htmlentities(strip_tags($data)))); } incase you want to see my jquery code, but i know its not related to this //ajax call $.ajax({ type:"POST", url:"server.php", datatype:"json", success: function(data){ console.log(data); } Also attaching both the files // $row=mysqli_fetch_array($result,MYSQLI_ASSOC); database.php index.html server.php
  5. Hello, I am trying to save image in mysql table using blob. I am show you my code [form page and backend page for insertion], please let me know where i am wrong ? <!DOCTYPE html> <html> <head> <title>Forms</title> <link href="css/kendo.metro.min.css"rel="stylesheet"> <link href="css/kendo.common.min.css" rel="stylesheet"> <script src="js/jquery.min.js"></script> <script src="js/kendo.web.min.js"></script> <script src="js/kendo.upload.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $('#btnSubmit').click(function(){ $.ajax({ type: "POST", url: 'data/create_new_property.php', data: "buildername=" + $('#buildername').val() + "&projectname=" + $('#projectname').val() + "&files=" + $('#files').val(), success: function(data){ $('#status').html(data); $('#buildername').val(''); $('#projectname').val(''); $('#files').val(''); } }); }); }); </script> </head> <body> <div id="example" class="k-content"> <div> <ul class="forms"> <li> <input type="text" class="k-textbox" id="buildername" value="Builder Name" onblur="if (this.value == '') {this.value = 'Builder Name';}" onfocus="if (this.value == 'Builder Name') {this.value = '';}"/> </li> <li> <input type="text" class="k-textbox" id="projectname" value="Project Name" onblur="if (this.value == '') {this.value = 'Project Name';}" onfocus="if (this.value == 'Project Name') {this.value = '';}"/> </li> <li> <input type="text" class="k-textbox" id="location" value="Location" onblur="if (this.value == '') {this.value = 'Location';}" onfocus="if (this.value == 'Location') {this.value = '';}"/> </li> <li> <input type="text" class="k-textbox" id="budget" value="Budget" onblur="if (this.value == '') {this.value = 'Budget';}" onfocus="if (this.value == 'Budget') {this.value = '';}"/> </li> <li> <input type="text" class="k-textbox" id="propertytype" value="Property Type" onblur="if (this.value == '') {this.value = 'Property Type';}" onfocus="if (this.value == 'Property Type') {this.value = '';}"/> </li> <li> <input name="files" id="files" type="file" /> </li> <li> <input type="text" class="k-textbox" id="area" value="Area" onblur="if (this.value == '') {this.value = 'Area';}" onfocus="if (this.value == 'Area') {this.value = '';}"/> </li> <li> <button class="k-button" id="btnSubmit">Save Project</button> </li> </ul> <style scoped> .forms { float: left; } .forms li { margin-bottom: 5px; list-style: none; } .forms li > * { width: 400px; } </style> </div> </div> </body> </html> php code to Insert data in mysql <?php header('Content-Type: application/json'); header('Access-Control-Allow-Origin: *'); header("Access-Control-Allow-Methods: POST, GET"); header("Access-Control-Allow-Headers: x-requested-with"); mysql_connect("localhost", "root", "") or die("Connection Failed"); mysql_select_db("property")or die("Connection Failed"); $bname = $_POST['buildername']; $pname = $_POST['projectname']; $uploadfiles = addslashes (file_get_contents($_FILES['files']['tmp_name'])); $image = getimagesize($_FILES['files']['tmp_name']);//to know about image type etc $imgtype = $image['mime']; //$query = "UPDATE test SET password = '$password' WHERE name = '$user'"; $query = "INSERT INTO projects (buildername, projectname, img) VALUES('$bname','$pname','$uploadfiles')"; if(mysql_query($query)){ echo "updated";} else{ echo "fail";} ?> Please correct me where i am wrong. Thanks a lot for your time
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.