Note that there are some explanatory texts on larger screens.

plurals
  1. PORemote Databasing
    primarykey
    data
    text
    <p>I'm trying to use a web service to store/retrieve info from a remote SQL database. For some reason empty strings are being inserted into the DB rather than the strings I want stored.</p> <p>What I need is to store the strings deviceID &amp; dateStamp if no entry in DB exists with deviceID.</p> <p>DB table name is trials, and the columns are: _id | device_id | install_date</p> <p>Note: Connects and interacts with database, just stores "" and "" instead of the strings.</p> <p>Can someone please tell me why this is? This is my first time I've tried this kind of thing so having a lot of trouble and trying to modify snippets I found to my needs.</p> <p>Here is my java code:</p> <pre><code>import java.io.InputStream; import java.util.ArrayList; import java.util.Date; import java.util.List; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.HttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.provider.Settings.Secure; import android.widget.Toast; public class LicenseCheck extends Activity { String deviceID="",dateStamp=""; byte[] data; HttpPost httppost; StringBuffer buffer; HttpResponse response; HttpClient httpclient; InputStream inputStream; List&lt;NameValuePair&gt; nameValuePairs; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final String android_id = Secure.getString(getApplicationContext().getContentResolver(),Secure.ANDROID_ID); deviceID = android_id; Date now = new Date(); dateStamp = String.valueOf(now); try { httpclient = new DefaultHttpClient(); httppost = new HttpPost("http://99.57.234.12/Main.php"); // Add your data nameValuePairs = new ArrayList&lt;NameValuePair&gt;(2); nameValuePairs.add(new BasicNameValuePair("device_id", deviceID)); nameValuePairs.add(new BasicNameValuePair("install_date", dateStamp)); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request response = httpclient.execute(httppost); inputStream = response.getEntity().getContent(); data = new byte[256]; buffer = new StringBuffer(); int len = 0; while (-1 != (len = inputStream.read(data)) ) { buffer.append(new String(data, 0, len)); } inputStream.close(); } catch (Exception e) { Toast.makeText(LicenseCheck.this, "error"+e.toString(), Toast.LENGTH_LONG).show(); } if(buffer.charAt(0)=='Y') { Toast.makeText(LicenseCheck.this, "working: " + buffer.toString() + ".", Toast.LENGTH_LONG).show(); Move_to_next(); LicenseCheck.this.finish(); } else { Toast.makeText(LicenseCheck.this, "Trial Started", Toast.LENGTH_LONG).show(); Move_to_next(); LicenseCheck.this.finish(); } } public void Move_to_next() { startActivity(new Intent(this, MainMenu.class)); } } </code></pre> <p>Here is the PHP:</p> <pre><code>&lt;?php require_once('Connections.php'); mysql_select_db($database_localhost,$localhost); $device = $_POST['device_id']; $date = $_POST['install_date']; $query_search = "select * from trials where device_id = '".$device."'"; $query_exec = mysql_query($query_search) or die(mysql_error()); $rows = mysql_num_rows($query_exec); if($rows --&gt; 0) { echo "Y"; $result = mysql_query("SELECT device_id,install_date FROM trials WHERE device_id = '".$device."'"); if (!$result) { echo 'Could not run query: ' . mysql_error(); exit; } $row = mysql_fetch_row($result); echo $row[0]; // device_id echo $row[1]; // install_date } else { echo "N"; mysql_query("INSERT INTO trials (device_id, install_date) VALUES ( '".$device."', '".$date."')") or die (mysql_error()); } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload