Skip to content

Instantly share code, notes, and snippets.

@evilnapsis
Created June 21, 2018 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evilnapsis/966a09377785a3df1e9ddb00fbdafec2 to your computer and use it in GitHub Desktop.
Save evilnapsis/966a09377785a3df1e9ddb00fbdafec2 to your computer and use it in GitHub Desktop.
Servicio web para servir contactos
<?php
/*
@author evilnapsis
*/
$con = new mysqli("localhost","root","","contactapp");
if(isset($_GET["opt"]) && $_GET["opt"]=="all"){
$sql = "select * from contact";
$query = $con->query($sql);
$data = array();
while($r = $query->fetch_assoc()){
$data[] = $r;
}
echo json_encode($data);
}
else if(isset($_GET["opt"]) && $_GET["opt"]=="add"){
$sql = "insert into contact (name,lastname,address,phone,email) values (\"$_POST[name]\",\"$_POST[lastname]\",\"$_POST[address]\",\"$_POST[phone]\",\"$_POST[email]\" )";
$con->query($sql);
echo json_encode(array("status"=>"success"))
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment