Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Collections.Specialized;
- using System.Linq;
- using System.Net;
- using System.Text;
- using Android.App;
- using Android.Content;
- using Android.Graphics;
- using Android.OS;
- using Android.Runtime;
- using Android.Support.Design.Widget;
- using Android.Support.V7.App;
- using Android.Views;
- using Android.Widget;
- namespace CPDEP1
- {
- [Activity(Label = "Formulaire d'enregistrement", Theme="@style/Theme.AppCompat.Light")]
- public class FormActivity : AppCompatActivity
- {
- CoordinatorLayout FrootLayout;
- protected override void OnCreate(Bundle savedInstanceState)
- {
- base.OnCreate(savedInstanceState);
- FrootLayout = FindViewById<CoordinatorLayout>(Resource.Id.FcoordLayout);
- SetContentView(Resource.Layout.Form);
- var inputNom = FindViewById<EditText>(Resource.Id.nom);
- var inputPrenom = FindViewById<EditText>(Resource.Id.pren);
- var inputTel = FindViewById<EditText>(Resource.Id.tel);
- var inputID = FindViewById<EditText>(Resource.Id.iden);
- var inputDep = FindViewById<EditText>(Resource.Id.dep);
- var inputCom = FindViewById<EditText>(Resource.Id.com);
- var savebtn = FindViewById<Button>(Resource.Id.save);
- var inputAdresse = FindViewById<EditText>(Resource.Id.adresse);
- var inputCourriel = FindViewById<EditText>(Resource.Id.email);
- savebtn.Click += delegate
- {
- string nom = inputNom.Text;
- string prenom = inputPrenom.Text;
- string tel = inputTel.Text;
- string id = inputID.Text;
- string dep = inputDep.Text;
- string com = inputCom.Text;
- string adress = inputAdresse.Text;
- string courriel = inputCourriel.Text;
- //REceiving value from an activity
- //string user = Intent.GetStringExtra("User");
- //string pass = Intent.GetStringExtra("Password");
- if (nom == null || prenom == null || tel == null || id == null || dep == null || com == null || adress == null || courriel == null)
- {
- ////////////SSNACKBAR///////////
- Snackbar snack = Snackbar.Make(FrootLayout, "Empty Field", Snackbar.LengthShort)
- .SetAction("", (view) =>
- {
- Toast.MakeText(this, "OK", ToastLength.Short).Show();
- }).SetActionTextColor(Color.ParseColor("#000000"));
- View SnackView = snack.View;
- SnackView.SetBackgroundColor(Color.ParseColor("#E72222"));
- snack.Show();
- }
- else
- {
- WebClient client = new WebClient();
- Uri uri = new Uri("http://localhost/CRUDSERVICE/CreateContact.php");
- NameValueCollection parameters = new NameValueCollection();
- parameters.Add("Nom", nom);
- parameters.Add("Prenom", prenom);
- parameters.Add("Tel", tel);
- parameters.Add("Dep", dep);
- parameters.Add("Com", com);
- parameters.Add("Adress", adress);
- parameters.Add("Courriel", courriel);
- client.UploadValuesAsync(uri, parameters);
- }
- };
- }
- // }
- }
- <?php
- class ConnectionInfo
- {
- public $mServerName;
- public $mConnectionInfo;
- public $conn;
- public function GetConnection()
- {
- $this->mServerName = 'localhost';
- $this->mConnectionInfo = array("Database"=>"formation", "UID"=>"root", "PWD"=>"cpdep");
- $this->conn = sqlsrv_connect($this->mServerName,$this->mConnectionInfo);
- return $this->conn;
- }
- }
- ?>
- <?php
- require_once(dirname(__FILE__).'/ConnectionInfo.php');
- if (isset($_POST['Nom']) && isset($_POST['Prenom']) && isset($_POST['Tel']) && isset($_POST['Dep']) && isset($_POST['Com']) && isset($_POST['Adress']) && isset($_POST['Courriel']))
- {
- //Get the POST variables
- $mNom = $_POST['Nom'];
- $mPrenom = $_POST['Prenom'];
- $mTel = $_POST['Tel'];
- $mDep = $_POST['Dep'];
- $mCom = $_POST['Com'];
- $mAdress = $_POST['Adress'];
- $mCourriel = $_POST['Courriel'];
- //Set up our connection
- $connectionInfo = new ConnectionInfo();
- $connectionInfo->GetConnection();
- if (!$connectionInfo->conn)
- {
- //Connection failed
- echo 'No Connection';
- }
- else
- {
- //Insert new contact into database
- $query = 'INSERT INTO thinktank (nom, prenom, telephone, departement, commune, adresse, courriel) VALUES (?, ?, ?, ?, ?, ?, ?)';
- $parameters = array($mNom, $mPrenom, $mTel, $mDep, $mCom, $mAdress, $mCourriel);
- //Execute query
- $stmt = sqlsrv_query($connectionInfo->conn, $query, $parameters);
- if (!$stmt)
- { //The query failed
- echo 'Query Failed';
- }
- else
- {
- //The query succeeded, now echo back the new contact ID
- $query = "SELECT IDENT_CURRENT('Contacts') AS NewID";
- $stmt = sqlsrv_query($connectionInfo->conn, $query);
- $row = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_ASSOC);
- echo $row['NewID'];
- }
- }
- }
- ?>
- String prenom="john";
- String nom="doe";
- String tel="025545";
- String dep="security";
- String com="somecom";
- String adress="street431";
- String courriel="youremail@gmail.com";
- // let's build our link
- String link="http://localhost/CRUDSERVICE/CreateContact.php?Nom="+nom+"&Prenom="+prenom+"&Tel="+tel+"&Dep="+dep+"&Com="+com+"&Adress+"+adress+"&Courriel="+courriel;
- WebClient wc=new WebClient(); // don't forget using System.Net;
- String res=wc.DownloadString(link); // res is data printed by echo
- if(res.equals("No Connection ") || res.equals("Query Failed"))
- {
- // something went wrong
- }
- else
- {
- }
Add Comment
Please, Sign In to add comment