Webstudies
Pages
Sunday, 16 June 2019
Friday, 7 September 2018
Insert data using Angular and php
Index.php
<html ng-app="myapp">
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
</head>
<body style="background: gray;"><br><br>
<div class="container" style="width:500px;">
<h3 align="center" style="color: white;">AngularJS Tutorial With PHP</h3>
<div ng-controller="userctrl" ng-init="displayData()">
<label style="color: white;">Name</label>
<input type="text" ng-model="nm" class="form-control">
{{nm}}
<br>
<label style="color: white;">Email</label>
<input type="test" ng-model="email" class="form-control">
{{email}}
<br>
<label style="color: white;">Country</label>
<input type="text" ng-model="country" class="form-control">
{{country}}
<br>
<input type="submit" name="btnInsert" class="btn btn-info" ng-click="insertData()" value="Insert">
<br><br>
<table class="table table-bordered">
<tr>
<th>S.no</th>
<th>Name</th>
<th>Email</th>
<th>Country</th>
<th>Edit</th>
<th>Delete</th>
</tr>
<tr ng-repeat="x in names">
<td> {{x.id}} </td>
<td> {{x.name}} </td>
<td> {{x.email}} </td>
<td> {{x.country}} </td>
<td> <button ng-click="updateData(x.id, x.name, x.email, x.country)" class="btn btn-info btn-xs">Update</button> </td>
<td> <button ng-click="deleteData(x.id)" class="btn btn-danger btn-xs">Delete</button> </td>
</tr>
</table>
</div>
</div>
</body>
</html>
<script>
var app = angular.module("myapp",[]);
app.controller("userctrl", function($scope, $http){
$scope.insertData = function(){
$http.post(
"insert.php",
{'nm':$scope.nm, 'email':$scope.email, 'country':$scope.country}
).success(function(data){
alert(data);
$scope.nm = null;
$scope.email = null;
$scope.country = null;
$scope.displayData();
});
}
$scope.displayData = function(){
$http.get("display.php")
.success(function(data){
$scope.names = data;
});
}
});
</script>
Insert.php
<?php
$con = mysqli_connect("localhost", "root", "", "test");
$data = json_decode(file_get_contents("php://input"));
if (count($data) > 0) {
$nm = mysqli_real_escape_string($con, $data->nm);
$email = mysqli_real_escape_string($con, $data->email);
$country = mysqli_real_escape_string($con, $data->country);
$query = "insert into crud values(null,'$nm','$email','$country')";
if (mysqli_query($con, $query)) {
echo "Data Inserted";
}else{
echo "Error";
}
}
?>
Display.php
<?php
$con = mysqli_connect("localhost", "root", "", "test");
$output = array();
$query = "SELECT * FROM crud";
$result = mysqli_query($con, $query);
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
$output[] = $row;
}
echo json_encode($output);
}
?>
<html ng-app="myapp">
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
</head>
<body style="background: gray;"><br><br>
<div class="container" style="width:500px;">
<h3 align="center" style="color: white;">AngularJS Tutorial With PHP</h3>
<div ng-controller="userctrl" ng-init="displayData()">
<label style="color: white;">Name</label>
<input type="text" ng-model="nm" class="form-control">
{{nm}}
<br>
<label style="color: white;">Email</label>
<input type="test" ng-model="email" class="form-control">
{{email}}
<br>
<label style="color: white;">Country</label>
<input type="text" ng-model="country" class="form-control">
{{country}}
<br>
<input type="submit" name="btnInsert" class="btn btn-info" ng-click="insertData()" value="Insert">
<br><br>
<table class="table table-bordered">
<tr>
<th>S.no</th>
<th>Name</th>
<th>Email</th>
<th>Country</th>
<th>Edit</th>
<th>Delete</th>
</tr>
<tr ng-repeat="x in names">
<td> {{x.id}} </td>
<td> {{x.name}} </td>
<td> {{x.email}} </td>
<td> {{x.country}} </td>
<td> <button ng-click="updateData(x.id, x.name, x.email, x.country)" class="btn btn-info btn-xs">Update</button> </td>
<td> <button ng-click="deleteData(x.id)" class="btn btn-danger btn-xs">Delete</button> </td>
</tr>
</table>
</div>
</div>
</body>
</html>
<script>
var app = angular.module("myapp",[]);
app.controller("userctrl", function($scope, $http){
$scope.insertData = function(){
$http.post(
"insert.php",
{'nm':$scope.nm, 'email':$scope.email, 'country':$scope.country}
).success(function(data){
alert(data);
$scope.nm = null;
$scope.email = null;
$scope.country = null;
$scope.displayData();
});
}
$scope.displayData = function(){
$http.get("display.php")
.success(function(data){
$scope.names = data;
});
}
});
</script>
Insert.php
<?php
$con = mysqli_connect("localhost", "root", "", "test");
$data = json_decode(file_get_contents("php://input"));
if (count($data) > 0) {
$nm = mysqli_real_escape_string($con, $data->nm);
$email = mysqli_real_escape_string($con, $data->email);
$country = mysqli_real_escape_string($con, $data->country);
$query = "insert into crud values(null,'$nm','$email','$country')";
if (mysqli_query($con, $query)) {
echo "Data Inserted";
}else{
echo "Error";
}
}
?>
Display.php
<?php
$con = mysqli_connect("localhost", "root", "", "test");
$output = array();
$query = "SELECT * FROM crud";
$result = mysqli_query($con, $query);
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
$output[] = $row;
}
echo json_encode($output);
}
?>
Monday, 25 June 2018
Parse XML file and store data into database using php
abc.xml
<?xml version="1.0"?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.</description>
</book>
<book id="bk103">
<author>Corets, Eva</author>
<title>Maeve Ascendant</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-11-17</publish_date>
<description>After the collapse of a nanotechnology
society in England, the young survivors lay the
foundation for a new society.</description>
</book>
<book id="bk104">
<author>Corets, Eva</author>
<title>Oberon's Legacy</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2001-03-10</publish_date>
<description>In post-apocalypse England, the mysterious
agent known only as Oberon helps to create a new life
for the inhabitants of London. Sequel to Maeve
Ascendant.</description>
</book>
<book id="bk105">
<author>Corets, Eva</author>
<title>The Sundered Grail</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2001-09-10</publish_date>
<description>The two daughters of Maeve, half-sisters,
battle one another for control of England. Sequel to
Oberon's Legacy.</description>
</book>
<book id="bk106">
<author>Randall, Cynthia</author>
<title>Lover Birds</title>
<genre>Romance</genre>
<price>4.95</price>
<publish_date>2000-09-02</publish_date>
<description>When Carla meets Paul at an ornithology
conference, tempers fly as feathers get ruffled.</description>
</book>
<book id="bk107">
<author>Thurman, Paula</author>
<title>Splish Splash</title>
<genre>Romance</genre>
<price>4.95</price>
<publish_date>2000-11-02</publish_date>
<description>A deep sea diver finds true love twenty
thousand leagues beneath the sea.</description>
</book>
<book id="bk108">
<author>Knorr, Stefan</author>
<title>Creepy Crawlies</title>
<genre>Horror</genre>
<price>4.95</price>
<publish_date>2000-12-06</publish_date>
<description>An anthology of horror stories about roaches,
centipedes, scorpions and other insects.</description>
</book>
<book id="bk109">
<author>Kress, Peter</author>
<title>Paradox Lost</title>
<genre>Science Fiction</genre>
<price>6.95</price>
<publish_date>2000-11-02</publish_date>
<description>After an inadvertant trip through a Heisenberg
Uncertainty Device, James Salway discovers the problems
of being quantum.</description>
</book>
<book id="bk110">
<author>O'Brien, Tim</author>
<title>Microsoft .NET: The Programming Bible</title>
<genre>Computer</genre>
<price>36.95</price>
<publish_date>2000-12-09</publish_date>
<description>Microsoft's .NET initiative is explored in
detail in this deep programmer's reference.</description>
</book>
</catalog>
xmlparsing.php
<?php
$con = mysqli_connect("localhost", "root", "", "comparetest3");
$xml = simplexml_load_file('xyz.xml');
foreach ($xml->catalog as $data) {
$book = $data->book;
$author = $data->author;
$title = $data->title;
$genre = $data->genre;
$price = $data->price;
$publish_date = $data->publish_date;
$description = $data->description;
$select = mysqli_query($con, "select * from booksdetail where book_id='$book'");
if (mysqli_num_rows($select) > 0) {
$query = mysqli_query($con, "update booksdetail set
book_id='$book',
book_author='$author',
book_title='$title',
book_genre='$genre',
book_price='$price',
book_pdate='$publish_date',
book_desc='$description'
where book_id='$book'") or die(mysqli_error($con));
}else{
$query = mysqli_query($con, "insert into booksdetail values(null,
'$book_id',
'$book_author', '$book_title',
'$book_genre', '$book_price',
'$book_pdate', '$book_desc')");
}
}
?>
<?xml version="1.0"?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.</description>
</book>
<book id="bk103">
<author>Corets, Eva</author>
<title>Maeve Ascendant</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-11-17</publish_date>
<description>After the collapse of a nanotechnology
society in England, the young survivors lay the
foundation for a new society.</description>
</book>
<book id="bk104">
<author>Corets, Eva</author>
<title>Oberon's Legacy</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2001-03-10</publish_date>
<description>In post-apocalypse England, the mysterious
agent known only as Oberon helps to create a new life
for the inhabitants of London. Sequel to Maeve
Ascendant.</description>
</book>
<book id="bk105">
<author>Corets, Eva</author>
<title>The Sundered Grail</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2001-09-10</publish_date>
<description>The two daughters of Maeve, half-sisters,
battle one another for control of England. Sequel to
Oberon's Legacy.</description>
</book>
<book id="bk106">
<author>Randall, Cynthia</author>
<title>Lover Birds</title>
<genre>Romance</genre>
<price>4.95</price>
<publish_date>2000-09-02</publish_date>
<description>When Carla meets Paul at an ornithology
conference, tempers fly as feathers get ruffled.</description>
</book>
<book id="bk107">
<author>Thurman, Paula</author>
<title>Splish Splash</title>
<genre>Romance</genre>
<price>4.95</price>
<publish_date>2000-11-02</publish_date>
<description>A deep sea diver finds true love twenty
thousand leagues beneath the sea.</description>
</book>
<book id="bk108">
<author>Knorr, Stefan</author>
<title>Creepy Crawlies</title>
<genre>Horror</genre>
<price>4.95</price>
<publish_date>2000-12-06</publish_date>
<description>An anthology of horror stories about roaches,
centipedes, scorpions and other insects.</description>
</book>
<book id="bk109">
<author>Kress, Peter</author>
<title>Paradox Lost</title>
<genre>Science Fiction</genre>
<price>6.95</price>
<publish_date>2000-11-02</publish_date>
<description>After an inadvertant trip through a Heisenberg
Uncertainty Device, James Salway discovers the problems
of being quantum.</description>
</book>
<book id="bk110">
<author>O'Brien, Tim</author>
<title>Microsoft .NET: The Programming Bible</title>
<genre>Computer</genre>
<price>36.95</price>
<publish_date>2000-12-09</publish_date>
<description>Microsoft's .NET initiative is explored in
detail in this deep programmer's reference.</description>
</book>
</catalog>
<?php
$con = mysqli_connect("localhost", "root", "", "comparetest3");
$xml = simplexml_load_file('xyz.xml');
foreach ($xml->catalog as $data) {
$book = $data->book;
$author = $data->author;
$title = $data->title;
$genre = $data->genre;
$price = $data->price;
$publish_date = $data->publish_date;
$description = $data->description;
$select = mysqli_query($con, "select * from booksdetail where book_id='$book'");
if (mysqli_num_rows($select) > 0) {
$query = mysqli_query($con, "update booksdetail set
book_id='$book',
book_author='$author',
book_title='$title',
book_genre='$genre',
book_price='$price',
book_pdate='$publish_date',
book_desc='$description'
where book_id='$book'") or die(mysqli_error($con));
}else{
$query = mysqli_query($con, "insert into booksdetail values(null,
'$book_id',
'$book_author', '$book_title',
'$book_genre', '$book_price',
'$book_pdate', '$book_desc')");
}
}
?>
Sunday, 13 May 2018
Send Mail in Codeigniter
Send E-mail In Codeigniter
View File
<?php echo form_open_multipart('pages/applynow');?>
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Shape your future with codizious technologies</h4>
</div>
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<div class="controls">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="name">Full Name *</label>
<input type="text" name="name" class="form-control" required>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="email">E-Mail Address *</label>
<input type="email" name="email" class="form-control" required>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="applay">Apply For *</label>
<input type="text" name="aply" class="form-control" required>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="msg">Message</label>
<textarea name="message" class="form-control" rows="6" required></textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="resume">Upload CV *</label>
<input type="file" name="file" class="form-control" required>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<div class="col-md-12" align="center">
<input type="submit" class="btn btn-success btn-send" value="Send Application">
</div>
</div>
</div>
<?php echo form_close(); ?>
Controller File
public function applynow(){
$cnfig['upload_path'] = './attachment/';
$cnfig['allowed_types'] = 'doc|docx|pdf';
$cnfig['max_size'] = 100000000000000;
$cnfig['encrypt_name'] = TRUE;
$this->load->library('upload', $cnfig);
if(!$this->upload->do_upload('file')){
echo 'select right file';
}
$sender_email = $this->input->post('email');
$name = $this->input->post('name');
$message = $this->input->post('message');
//$rsum = $this->input->post('file');
// Configure email library
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_port'] = 465;
$config['smtp_user'] = 'jpjadeja24@gmail.com';
$config['smtp_pass'] = 'rvjadeja$411';
// Load email library and passing configured values to email library
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
// Sender email address
$this->email->from($sender_email, $name);
// Receiver email address
$this->email->to('jadejajaypalsinhrj@gmail.com');
// Subject of email
$this->email->subject('apply for job');
// Message in email
$this->email->message($message);
//$path = $this->config->item('server_root');
//$file = $path.'/attachment/yourinfo.txt';
$path = set_realpath('attachment/'. $this->upload->data('file'));
$this->email->attach($path);
if ($this->email->send()) {
echo '<script>alert("Email Send Successfully!");</script>';
redirect('pages/career', 'refresh');
} else {
echo $this->email->print_debugger();
//$data['message_display'] = '<p class="error_msg">Invalid Gmail Account or Password !</p>';
}
}
Subscribe to:
Posts (Atom)