Commit 97e23cd6 authored by Jessica Suszek's avatar Jessica Suszek
Browse files

add plans -displaying but not working php

parent 06a62b39
This is a test file
\ No newline at end of file
<?php
// use column aliases if necessary to make referencing fields in result-set easier
echo "working ";
// $sql = "SELECT p.destination , p.startDate , p.endDate, p.description
// FROM myplan p
// WHERE 1";
// // query the database
// $result = mysqli_query($link, $sql);
// // update HTML content string with page title
// $content .= "<h1>MyPlans</h1>";
// // get number of rows in result-set
// $row_cnt = mysqli_num_rows($result);
// // check if there are rows to display...
// if ($row_cnt == 0) {
// // if not, output a suitable message
// $content .= "<p>No plans yet ! Time to make them</p>";
// } else {
// // otherwise, update the HTML in $content
// $content .= "<table cellpadding='2' border='1'>
// <thead align='left'>
// <tr>
// <th>Destination</th>
// <th> Availablity from </th>
// <th> to </th>
// <th> Description </th>
// </tr>
// </thead>
// <tbody>";
// // while there are rows, fetch each row as an associative array
// // while ($row = mysqli_fetch_assoc($result)) {
// // // append the content with more HTML containing row data
// // $content .= "<tr>
// // <td><a href='?page=user&id=".$row['id']."'>".$row['firstname']." ".$row['lastname']."</a></td>
// // <td>".$row['num_party']."</td>
// // </tr>"; // reference a field value in the array by its key!
// // }
// // free result set
// mysqli_free_result($result);
// $content .= "</tbody></table>";
// }
?>
\ No newline at end of file
......@@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
......
......@@ -28,4 +28,6 @@ dependencies {
compile 'com.android.volley:volley:1.0.0'
compile 'com.android.support:design:25.1.0'
testCompile 'junit:junit:4.12'
compile 'com.mcxiaoke.volley:library:1.0.18'
}
......@@ -23,7 +23,11 @@
android:exported="true"
</activity>
<activity android:name=".SearchActivity" />
<activity android:name=".MyPlanActivity" />
<activity android:name=".MyPlanActivity">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MessageActivity"></activity>
</application>
......
package travelpals.travelpals;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.Button;
import android.widget.TextView;
import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
public class MyPlanActivity extends AppCompatActivity {
EditText destination, description, startDate, endDate;
TextView result;
Button add_plan, show;
RequestQueue requestQueue;
String insertUrl1 = "http://doc.gold.ac.uk/~jsusz001/software/MyPlans.php";
String showUrl1 ="http://doc.gold.ac.uk/~jsusz001/software/showPlans.php";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_plan);
destination = (EditText) findViewById(R.id.destination);
startDate = (EditText) findViewById(R.id.startDate);
endDate = (EditText) findViewById(R.id.endDate);
description =(EditText) findViewById(R.id.description);
add_plan = (Button) findViewById(R.id.button);
show = (Button) findViewById(R.id.button3);
result = (TextView) findViewById(R.id.result);
requestQueue = Volley.newRequestQueue(getApplicationContext());
show.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view){
JSONObject obj = new JSONObject();
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST,
showUrl1,obj, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray plans = response.getJSONArray("plans");
for(int i=0; i<plans.length(); i++){
JSONObject plan = plans.getJSONObject(i);
String destination = plan.getString("destination");
String startDate = plan.getString("startDate");
String endDate = plan.getString("endDate");
String description = plan.getString("description");
result.append(destination+ " " +startDate+" "+endDate+" "+description+ "" +
"\n" );
}
result.append("===\n");
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener(){
@Override
public void onErrorResponse(VolleyError error){
}
});
requestQueue.add(jsonObjectRequest);
}
});
add_plan.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
StringRequest request = new StringRequest(Request.Method.POST, insertUrl1, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
System.out.println(response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("destination", destination.getText().toString());
parameters.put("startDate", startDate.getText().toString());
parameters.put("endDate", endDate.getText().toString());
parameters.put("description", description.getText().toString());
return parameters;
}
};
requestQueue.add(request);
}
}
});
}
}
\ No newline at end of file
......@@ -10,4 +10,72 @@
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="travelpals.travelpals.MyPlanActivity">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="date"
android:ems="10"
android:layout_below="@+id/startDate"
android:layout_alignStart="@+id/startDate"
android:layout_marginTop="21dp"
android:id="@+id/endDate"
android:text="endDate" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="text"
android:text="destination"
android:ems="10"
android:id="@+id/destination"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="date"
android:ems="10"
android:id="@+id/startDate"
android:text="startDate"
android:layout_marginTop="29dp"
android:layout_below="@+id/destination"
android:layout_alignStart="@+id/destination" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="text"
android:text="description"
android:ems="10"
android:id="@+id/description"
android:layout_centerVertical="true"
android:layout_alignStart="@+id/endDate" />
<Button
android:text="Add Plan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"
android:layout_below="@+id/description"
android:layout_centerHorizontal="true" />
<Button
android:text="show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button"
android:layout_alignEnd="@+id/button"
android:id="@+id/button3" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:ems="10"
android:id="@+id/result"
android:layout_below="@+id/button3"
android:layout_alignStart="@+id/description" />
</RelativeLayout>
<?php
// define a connection 'handle'
$link = mysqli_connect(
'localhost',
'jsusz001',
'password',
'jsusz001_TravelPals'
);
// check connection succeeded
if (mysqli_connect_errno()) {
exit(mysqli_connect_error());
echo "Connection error";
}
?>
<?php
if($_SERVER["REQUEST_METHOD"]=="POST"){
include 'connection.php';
showPlan();
}
function showPlan(){
global $link;
$query = "SELECT destination , startDate , endDate, description FROM myplan WHERE user_id = '1'; ";
$result = mysqli_query($link, $query);
?>
\ No newline at end of file
testingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtesting
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment