I've been really struggling with this today. Can't seem to get it to work, all it does is navigates to 'add-entry.php?go' in the navbar, but goes grey then reloads the index.php with modal still intact with my entries in it.
Here's my html, including the form and javascript filter input.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ProSys Component Lookup</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> <!--Custom CSS -->
<link rel="stylesheet" href="css/main.css">
</head>
<body>
<!-- Wrapper -->
<div class="container-fluid">
<div class="col-xs-12">
<div class="col-xs-12">
<!-- Header -->
<div class="page-header">
<h1>ProSys Component Lookup</h1><br>
</div>
<!-- Main table content -->
<div class="container-fluid">
<button type="button" class="btn btn-primary btn-block" data-toggle="modal" data-target="#myModal">Add New Item</button><br>
<div class="modal fade" role="dialog" id="myModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Add New Item</h4>
</div>
<div class="modal-body">
<form method="post" action="add-entry.php?go" role="form">
<div class="form-group">
<label for="location">Location:</label>
<input type="text" class="form-control" name="location">
</div>
<div class="form-group">
<label for="category">Category:</label>
<select class="form-control" name="category">
<option>Processor</option>
<option>Diode</option>
<option>Fuse</option>
<option>Regulator</option>
<option>Capacitor</option>
<option>Inductor</option>
<option>LED</option>
<option>Gate</option>
<option>Modem</option>
<option>Transceiver</option>
<option>Thermistor</option>
<option>Load Switch</option>
<option>Op Amp</option>
<option>Optocoupler</option>
<option>Line Driver</option>
<option>ESD Protection</option>
<option>ADC</option>
<option>RTC</option>
</select>
</div>
<div class="form-group">
<label for="manufacturer">Manufacturer:</label>
<input type="text" class="form-control" name="manufacturer">
</div>
<div class="form-group">
<label for="description">Description:</label>
<textarea type="text" class="form-control" name="description" rows="5"></textarea>
</div>
<div class="form-group">
<label for="packagesize">PackageSize:</label>
<input type="text" class="form-control" name="packagesize">
</div>
<div class="form-group">
<label for="category">Supplier:</label>
<select class="form-control" name="supplier">
<option>Farnell</option>
<option>RS</option>
<option>Rapid</option>
</select>
</div>
<div class="form-group">
<label for="suppliernumber">Supplier Number:</label>
<input type="text" class="form-control" name="suppliernumber">
</div>
<div class="form-group">
<label for="stock">Stock:</label>
<input type="text" class="form-control" name="stock">
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-default">Add</button>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- Search box -->
<div class="col-md-3">
<form class="styled">
<input type="text" class="form-control" onkeyup="myFunctionOne()" id="myInput" placeholder="Search..">
</form><br>
</div>
<div class="panel">
<div class="panel-body">
<div class="row">
<div class="col-xs-12">
<table class="table table-hover" id="table_demo">
<thead>
<tr>
<th>Location</th>
<th>Manufacturer</th>
<th>Description</th>
<th>PackageSize</th>
<th>Supplier</th>
<th>SupplierNumber</th>
<th>Stock</th>
</tr>
</thead>
<tbody id="myTable">
<tr>
<!-- Database connect and display as table -->
<?php
include("dbconnect.php");
$result = mysql_query("SELECT DrawLocation, Manufacturer, Description, PackageSize, Supplier, SupplierNumber, Stock FROM complibrary");
while($complibrary = mysql_fetch_array($result))
{
echo"<td>".$complibrary['DrawLocation']."</td>";
echo"<td>".$complibrary['Manufacturer']."</td>";
echo"<td>".$complibrary['Description']."</td>";
echo"<td>".$complibrary['PackageSize']."</td>";
echo"<td>".$complibrary['Supplier']."</a></td>";
//IF statement adds in links for web search via SupplierNumber
if ($complibrary['Supplier'] == 'Farnell') {
echo"<td><a target='_blank' href='http://uk.farnell.com/search?st=".$complibrary['SupplierNumber']."'>".$complibrary['SupplierNumber']."</a></td>";
} elseif ($complibrary['Supplier'] == 'RS') {
echo"<td><a target='_blank' href='http://uk.rs-online.com/web/c/?sra=oss&r=t&searchTerm=".$complibrary['SupplierNumber']."'>".$complibrary['SupplierNumber']."</a></td>";
} elseif ($complibrary['Supplier'] == 'Rapid') {
echo"<td><a target='_blank' href='https://www.rapidonline.com/Catalogue/Search?query=".$complibrary['SupplierNumber']."'>".$complibrary['SupplierNumber']."</a></td>";
} else {
echo"<td>".$complibrary['SupplierNumber']."</td>";
}
//IF statement end
echo"<td>".$complibrary['Stock']."</td>";
echo "</tr>";
}
mysql_close($conn);
?>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
<!-- Latest jQuery -->
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<!-- Filtering script -->
<script>
function myFunctionOne() {
var input, filter, table, tr, td, i;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("myTable");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[2];
if (td) {
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
</script>
</html>
And here's my add-entry.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<?php
if (isset($_POST['location'])){
$hostname = "localhost";
$username = "root";
$password = "";
$dbname = "componentlookup";
$conn = mysql_connect($hostname, $username, $password);
if (!$conn) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db($dbname, $conn);
$location = $_POST['location'];
$category = $_POST['category'];
$manufacturer = $_POST['manufacturer'];
$description = $_POST['description'];
$packagesize = $_POST['packagesize'];
$supplier = $_POST['supplier'];
$suppliernumber = $_POST['suppliernumber'];
$stock = $_POST['stock'];
$query = mysql_query("INSERT INTO 'complibrary' (ID, DrawLocation, Category, Manufacturer, Description, PackageSize, Supplier, SupplierNumber, Stock) VALUES ('NULL', '$location', '$category', '$manufacturer', '$description', '$packagesize', '$supplier', '$suppliernumber', '$stock')");
echo "Item added sucessfully. Click <a href='index.php'>HERE</a> to go back.";
mysql_close($conn);
}
?>
</body>
</html>
Any ideas?
I think you should put data-dismiss="modal" on the add button to close the window.
Also, I think you should not use mysql connection. Better, use mysqli or PDO.
Related
I'm trying to update a text field (Price) whenever a drop-down menu (List of Products) item is selected. the text filed will show the selected item's price. I want to do this using ajax and i'm still new to this.
My code so far:
index.php
<?php
include 'Connection.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="Style.css">
<title>Shopping Cart</title>
</head>
<body>
<div id="mainPadding">
<h1 class="Shopping Title">The Shopping Items</h1>
<form class="form-horizontal">
<fieldset class="border p-2">
<legend class="w-auto">Contact Details:</legend>
<div class="form-group">
<label class="control-label col-sm-2" for="name">Name:</label>
<div class="col-sm-3">
<input type="name" required class="form-control" id="name" placeholder="Enter Your Name">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="email">Email:</label>
<div class="col-sm-3">
<input type="email" pattern="[a-z0-9._%+-]+#[a-z0-9.-]+\.[a-z]{2,}$" class="form-control" required id="email" placeholder="e.g. shop#shop.shop">
</div>
</div>
</fieldset>
<fieldset class="border p-2">
<legend class="w-auto">Available Items:</legend>
<div class="form-group">
<label class="col-lg-3 control-label">Item:</label>
<div class="col-sm-3">
<div class="ui-select">
<select id="ItemListDropDown" class="selectpicker" data-live-search="true">
<div id="itemList">
<?php
$sql = "SELECT Product_Name FROM products WHERE Availability = 1";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0)
while ($row = mysqli_fetch_assoc($result))
echo "<option>" . $row["Product_Name"] . "</option>";
?>
</div>
</select>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="price">Price</label>
<div class="col-sm-3">
<input type="text" disabled class="form-control" id="priceTxt">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="price">Quantity (between 1 and 5):</label>
<div class="col-sm-3">
<input type="number" maxlength="1" min="1" max="5" class="form-control" id="priceTxt">
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label"></label>
<div class="col-md-8">
<input id="addToCart" type="button" class="btn btn-primary" value="Add to the Cart">
</div>
</div>
</fieldset>
<fieldset class="border p-2">
<legend class="w-auto">Invoice Details:</legend>
<div class="form-group">
<table class="table table-striped" id="ItemTable">
<thead>
<tr>
<th scope="col">Sr.</th>
<th scope="col">Item Name</th>
<th scope="col">Price</th>
<th scope="col">Count</th>
<th scope="col">Total</th>
<th scope="col">Delete</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row"></th>
<td id="ItemName"></td>
<td id="Price"></td>
<td id="Count"></td>
<td id="Total"></td>
<td id="DeleteButton"></td>
</tr>
</tbody>
</table>
<div class="form-group">
<label class="col-md-3 control-label"></label>
<div class="col-md-8">
<input id="PrintAndSend" type="submit" class="btn btn-primary" value="Print and Send to Email">
</div>
</div>
</div>
</fieldset>
</form>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<script src="Javascript.js"></script>
</body>
</html>
Javascrpt.js
$(document).ready(function() {
$("#ItemListDropDown").change(function() {
$("#itemList").load("load-product.php")
// $("#priceTxt").attr("value", price);
});
});
load-product.php
<?php
include 'Connection.php';
$sql = "SELECT Product_Name FROM products WHERE Availability = 1";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0)
while ($row = mysqli_fetch_assoc($result))
echo "<option>" . $row["Product_Name"] . "</option>";
?>
I'm trying to do a few things using ajax, solving this will set me up for the rest.
Snake, you don't need Ajax to get your product price, instead just use a data-* attribute:
in your php (NOT the load-product.php file):
<?php
$sql = "SELECT Product_id, Product_Name, Product_price FROM products WHERE Availability = 1";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0)
echo "<option value='default' data-price='default'>Choose a item </option>";
while ($row = mysqli_fetch_assoc($result))
echo "<option value='{$row["Product_id"}' data-price='{$row["Product_price"]}'>" . $row["Product_Name"] . "</option>";
?>
then in your javascript do this to get your item price:
// JavaScript using jQuery
$(function(){
$('#ItemListDropDown').change(function(){
var selected = $(this).find('option:selected');
var extra = selected.data('price');
$("#priceTxt").val(extra); // set your input price with jquery
$("#priceTxt").prop('disabled',false);//set the disabled to false maybe you want to edit the price
...
});
});
// Plain old JavaScript
var sel = document.getElementById('ItemListDropDown');
var selected = sel.options[sel.selectedIndex];
var extra = selected.getAttribute('data-price');
var priceInput = document.getElementById('priceTxt');
priceInput.disabled = false;
priceInput.value =extra;
Hope it helps =)
i am making a dynamic form right now, duplicating the form is easy, but there is one textfield where the value is from the database, the problem is, the value from the database cant be duplicated. the point is im trying to duplicate a value in php, here is the problem, and is there anyway to insert a data into database using <label> ? because duplicating the value using <label> is a succsed
here is my code.
<?php
include 'config/db_connect.php';
if(isset($_POST['submit'])){
for($i = 0; $i <= count($_POST['kode'])-1;$i++){
$selectidmax =mysqli_query($con, "SELECT max(jenis) as maxjenis FROM t_produk WHERE jenis LIKE 'SS%'");
$hslidmax=mysqli_fetch_array($selectidmax);
$idmax=$hslidmax['maxjenis'];
$nourut = (int) substr($idmax, 2,3);
$nourut++;
$IDbaru = "SS" . sprintf("%03s", $nourut);
$kodep = $_POST['kode'][$i];
$kodeproduk = $_POST['kp'][$i];
$produk = $_POST['produk'][$i];
$bunga = $_POST['bunga'][$i];
$ket = $_POST['ket'][$i];
$query = mysqli_query($con, "INSERT INTO t_produk(kode_cu,jenis,kode_produk,produk,bunga,keterangan)
VALUES (
'$kodep',
'$IDbaru',
'$kodeproduk',
'$produk',
'$bunga',
'$ket')
");
}
if($query){
header("location:home_cu.php");
}else{
echo "gagal" . mysqli_error($con);
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Form Simpanan Saham</title>
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="stylesheet" type="text/css" href="css/style1.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
</head>
<body>
<div class="w3-bar w3-black">
Home
Menu Data Cu
Menu Data Kebijakan
Menu Data Modifikasi
</div>
<br>
<div class="container">
<form action="form_saham.php" method="post">
<h1 class="text-center">Produk Pinjaman</h1>
<div class="form-content">
<div class="row">
<div class="col-md-12">
<p><button type="button" id="btnAdd" class="btn btn-primary">Add More</button></p>
<br/>
</div>
</div>
<div class="row group">
<div class="col-md-3">
<div class="form-group">
<?php
include 'config/db_connect.php';
$kode = $_GET['kode_cu'];
$query = mysqli_query($con,"SELECT * FROM t_cu WHERE kode_cu = '$kode'");
while ($hasil = mysqli_fetch_array($query) ) {
?>
<label>Kode Produk :</label>
<input type="text" value="<?php echo $hasil['kode_cu']?>" name="kode[]" class="form-control">
<input type="text" name="kp[]" class="form-control"/>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Produk</label>
<input type="text" name="produk[]" class="form-control">
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label>Bunga</label>
<input type="text" name="bunga[]" class="form-control">
</div>
</div>
<div class="col-md-5">
<div class="form-group">
<label>Keterangan</label>
<textarea name="ket[]" class="form-control" rows="3"></textarea>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<button type="button" class="btn btn-danger btnRemove">Remove</button>
</div>
</div>
</div>
</div>
<button type="submit" name="submit" class="btn btn-primary">Submit</button>
</form>
</div>
<?php } ?>
<script src="assets/js/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="assets/js/bootstrap.min.js"></script>
<script src="jquery.multifield.min.js"></script>
<script>
$('.form-content').multifield({
section: '.group',
btnAdd:'#btnAdd',
btnRemove:'.btnRemove',
});
</script>
</body>
</html>
Ok, i found the question by myself, i just move the <input type="text" value="<?php echo $hasil['kode_cu']?>" name="kode[]" class="form-control"> to the top, so this textfield won't get duplicated, and then in the database value i changed the '$kodep', into (SELECT kode_cu FROM t_cu WHERE kode_cu = '$kodep'), Thank you for everyone who tries to help
[EDIT]just put the post data in a var and delete $scope.
$scope.deleteData = function(email) {
if(confirm("Are you sure you want to delete this record?")){
var email1= email; $http.post('<?php echo site_url("index.php/user/delete_user");?>', {'email':email1}).error(function(){ console.log("error"); });
}
}
whenever i press delete button nothing happens.
please check the code and please reply with the solution. network payload pass nothing {}.
view/user_view.php
<!DOCTYPE html >
<html lang="en" ng-app="userApp">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script>
<script type="text/javascript" src="<?php echo base_url('assets/jquery/jquery-3.1.1.min.js'); ?>"></script>
<script type="text/javascript" src="<?php echo base_url('assets/bootstrap/js/bootstrap.min.js'); ?>"></script>
<link href="<?php echo base_url('assets/bootstrap/css/bootstrap.min.css'); ?>">
<script type="text/javascript">
/*function userController($scope,$http) {
$scope.users = [];
$http.get('<?php echo site_url('index.php/user/user_list'); ?>').success(function($data){ $scope.users=$data; });
}*/
var app = angular.module('userApp', []);
app.controller('userController', function($scope, $http) {
//$scope.buttonName = "Add";
$scope.deleteData = function() {
/*$http.post("<?php echo base_url(); ?>index.php/User/delete_user/",{'id':$scope.id})
.success(function(data,status,headers,config){
$scope.message = "Deleted Successfully!";
});
*/
$http.post('<?php echo site_url('index.php/user/delete_user');?>',
{'email':$scope.email}).error(function(){
console.log("error");
})
}
$scope.displayUsers = function() {
$scope.users = [];
$http.get('<?php echo site_url("index.php/user/user_list"); ?>').success(function($data){ $scope.users=$data; });
}
$scope.insertData = function(){
$http.post('<?php echo site_url('index.php/user/insert_user');?>',
{
'name':$scope.name,
'gender':$scope.gender,
'email':$scope.email,
'address':$scope.address,
'phone':$scope.phone
}).error(function() {
console.log("Error");
});
}
});
</script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body ng-controller="userController">
<!-- ng-app : which tells the Angular framework to parse data from this div -->
<div class="container" ng-init="displayUsers()">
<button class="btn" data-toggle="modal" data-target="#myModal">Add Users</button>
<div class="row">
<div class="col-lg-12 col-md-12">
<input type="search" class="form-control" ng-model="searchUser" placeholder="Live Search">
<table class="table table-bordered table-condensed table-responsive" ng-controller="userController">
<thead>
<tr>
<td>Select</td>
<td>Name</td>
<td>Gender</td>
<td>Email</td>
<td>Address</td>
<td>Phone Number</td>
<td>Action</td>
</tr>
</thead>
<tbody>
<tr ng-repeat="user in users | filter:searchUser">
<td><input type="checkbox"></td>
<td class="hidden">{{user.id}}</td>
<td>{{user.name}}</td>
<td>{{user.gender}}</td>
<td>{{user.email}}</td>
<td>{{user.address}}</td>
<td>{{user.phone}}</td>
<td>
<button class="btn btn-primary">Edit</button>
<button class="btn" name="btnDelete" ng-click="deleteData(user.email)" value="delete">Delete</button></td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
<div class="col-md-12">
<form class="form form-horizontal">
<div class="form-group hidden">
<label for="name">id</label>
<input type="hidden" class="form-control" ng-model="id" id="name">
</div>
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" ng-model="name" id="name">
</div>
<div class="form-group">
<label for="gender">Gender</label>
<input type="radio" id="gender" ng-model="gender" value="male">Male
<input type="radio" id="gender" ng-model="gender" value="female">Female
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="text" class="form-control" ng-model="email" id="email">
</div>
<div class="form-group">
<label for="address">Address</label>
<input type="text" class="form-control" ng-model="address" id="address">
</div>
<div class="form-group">
<label for="phone">Phone Number</label>
<input type="text" class="form-control" ng-model="phone" id="phone">
</div>
<button type="button" class="btn btn-primary" ng-click="insertData()" type="submit">Insert</button>
</form>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
controller/User.php
<?php
defined('BASEPATH') OR EXIT ('DIRECT ACCESS IS NOT ALLOWED');
class User extends CI_Controller{
public function index(){
$this->load->view('user_view');
}
public function user_list(){
$data = $this->user_model->get_user_list();
$this->output->set_content_type('application/json')->set_output(json_encode($data));
}
public function insert_user(){
//$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';
$_POST = json_decode(file_get_contents('php://input'),true);
$data = $_POST;
$this->user_model->insert_user_data($data);
}
public function delete_user(){
$_POST = json_decode(file_get_contents('php://input'),true);
$email= $_POST['email'];
$this->user_model->delete_user_data($email);
}
}
?>
model/user_model.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class User_model extends CI_Model{
protected $table_name;
public function __construct(){
parent::__construct();
$this->table_name = 'user';
}
public function get_user_list(){
return $this->db->from($this->table_name)->get()->result_array();
}
public function insert_user_data($data){
$this->db->insert($this->table_name, $data);
}
public function delete_user_data($email){
$this->db->where('email',$email);
$this->db->delete('user');
}
}
?>
Network after click on delete.
The thing you are doing a wrong here is, passing email as an argument in function, you are not utilizing it:
$scope.deleteData = function(email) {
$http.post('<?php echo site_url('index.php/user/delete_user');?>',
{'email':email}).error(function(){
console.log("error");
})
}
use double quotes inside single quotes
$http.post('<?php echo site_url("index.php/user/delete_user");?>',
{'email':$scope.email}).error(function(){
console.log("error");
})
Hi I want to bring this information to insert multiple records from select
This all FORM
<?php
session_start();
//PUT THIS HEADER ON TOP OF EACH UNIQUE PAGE
if(!isset($_SESSION['id_user'])){
header("location:../index.php");
header("Content-type: text/html; charset=utf-8");
}
include "config.php";
$strSQL = "SELECT * FROM vn_order order by id_vn_order desc ";
$objQuery = mysqli_query($mysqli,$strSQL);
$sqlus = "SELECT * FROM vn_user WHERE id_user = '".$_SESSION['id_user']."' ";
$objQu = mysqli_query($mysqli,$sqlus);
$objResult = mysqli_fetch_array($objQu);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Limitless - Responsive Web Application Kit by Eugene Kopyov</title>
<!-- Global stylesheets -->
<link href='https://fonts.googleapis.com/css?family=Kanit&subset=thai,latin' rel='stylesheet' type='text/css'>
<link href="assets/css/icons/icomoon/styles.css" rel="stylesheet" type="text/css">
<link href="assets/css/bootstrap.css" rel="stylesheet" type="text/css">
<link href="assets/css/core.css" rel="stylesheet" type="text/css">
<link href="assets/css/components.css" rel="stylesheet" type="text/css">
<link href="assets/css/colors.css" rel="stylesheet" type="text/css">
<link href="assets/css/sweet-alert.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="assets/js/alert/sweet-alert.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script src="respond.js"></script>
<style type="text/css">
body {
font-family: 'Kanit', sans-serif;
}
</style>
</head>
<body onLoad="setPostBack();">
<?php require_once("inc/header_menu.php") ?>
<!-- /user menu -->
<?php require_once("inc/menu.php") ?>
<!-- Main content -->
<div class="content-wrapper">
<!-- Content area -->
<div class="content">
<!-- Basic datatable -->
<div class="panel panel-flat">
<div class="panel-heading">
<h5 class="panel-title">จองรถตู้</h5>
<div class="heading-elements">
<ul class="icons-list">
<li><a data-action="collapse"></a></li>
<li><a data-action="reload"></a></li>
<li><a data-action="close"></a></li>
</ul>
</div>
</div>
<div class="panel-body">
</div>
<form role="form" action="dorent.php" method="post" onSubmit="return doSubmit();">
<input type="hidden" value="1" name="id_user"/>
<input type="hidden" value="1" name="id_invoice"/>
<input type="hidden" value="1" name="travellist_id"/>
<input type="hidden" value="Approve" name="Status"/>
<div class="panel-body">
<div class="row">
<div class="col-md-6">
<fieldset>
<legend class="text-semibold"><i class="icon-reading position-left"></i> Personal details</legend>
<div class="form-group">
<label>ชื่อ</label>
<input type="text" class="form-control" placeholder="ชื่อ" name="rn_first_name" id="rn_first_name" value="<?php echo $objResult["firstname"];?>" readonly>
</div>
<div class="form-group">
<label>นามสกุล:</label>
<input type="text" class="form-control" placeholder="นามสกุล" name="rn_last_name" id="rn_last_name" value="<?php echo $objResult["lastname"];?>"readonly>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>E-mail</label>
<input type="text" class="form-control" placeholder="Email" name="" id="" value="<?php echo $objResult["email"];?>"readonly>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>เบอร์โทรศัพท์</label>
<input type="text" class="form-control format-phone-number" name="rn_tel" id="rn_tel" placeholder="เบอร์ติดต่อ" value="<?php echo $objResult["Tel"];?>"maxlength="10" readonly>
</div>
</div>
</div>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
var obj_a = $("#rn_amount");
var obj_b = $("#data_b");
// a เปลี่ยนเมื่อ keyup แล้ว b เปลี่ยน ตามเงื่อนไขค่า a
obj_a.on("keyup",function(){
var value_obj_a = parseInt($(this).val()); // เก็บค่า a ไว้ในตัวแปร (parseInt คือเปลงเป็นเลข)
if(value_obj_a>9){ // กำหนดเงื่อนไขให้กับค่า a
obj_b.val(2); // เปลี่ยนค่า b เป้น 3
}else{
obj_b.val(1); // เปลี่ยนค่า b เป็น 1
}
});
});
</script>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>จำนวนวนคนที่ไป</label>
<input type="text" name="rn_amount" id="rn_amount" value="" class="form-control"><br>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="display-block text-semibold">ประเภทรถตู้</label>
<select name="data_b" id="data_b" class="form-control">
<option value=""> Select </option>
<option value="1">9</option>
<option value="2">13</option>
</select>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<legend class="text-semibold"><i class="icon-truck position-left"></i> Shipping details</legend>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>วันที่จอง : (วันที่ไป)</label>
<input class="form-control" type="date" name="rn_gostart" id="rn_gostart">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>วันที่กลับ : (วันกลับ)</label>
<input class="form-control" type="date" name="rn_endstart" id="rn_endstart">
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>เวลาเดินทางไป</label>
<input class="form-control" type="time" name="time_gostart" id="time_gostart">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>เวลาเดินทางกลับ</label>
<input class="form-control" type="time" name="time_endstart" id="time_endstart">
</div>
</div>
</div>
<!-- เลือกสถานที่ท่องเที่ยว -->
<input type="hidden" id="txtNum" value="1" size="2" />
<table border="0" width="100%">
<thead>
<tr>
<th>
<div class="row">
<div class="col-md-10">
<div class="form-group">
<label class="display-block text-semibold"> จังหวัดที่ท่องเที่ยว</label>
<select name="province_id[]" id="selProvince" class="select-search">
<option value="">กรุณาเลือกจังหวัด</option>
<?php
include("connect.inc.php");
$SelectPr="SELECT * FROM province";
$QueryPro=mysql_query($SelectPr);
while($Pro=mysql_fetch_array($QueryPro)){
?>
<option value="<?=$Pro['province_id']?>"><?=$Pro['province_name']?></option>
<?php } ?>
</select>
</div>
</div>
</div>
</th>
<th>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label class="display-block text-semibold"> สถานที่ท่องเที่ยว</label>
<select id="selTravel" name="travel_id[]" class="select-search"><option value="">กรุณาเลือกจังหวัด</option></select>
</div>
</div>
</div>
</div>
</th>
<th>
</th>
</tr>
<tr><td><center>รายการที่เพิ่ม</center></td></tr>
</thead>
<tbody>
</tbody>
</table>
<div class="row">
<div class="form-group">
<div class="col-md-6">
<button type="button" id="btnP">เพิ่มรายการ</button>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label class="display-block text-semibold"> สถานที่ไปรับ</label>
<input class="form-control" type="text" name="rn_place" autocomplete="off">
</div>
</div>
</div>
<div class="form-group">
<label>สถานที่เพิ่มเติมระหว่างทาง</label>
<textarea rows="5" cols="5" class="form-control" name="vn_dtial" placeholder="Enter your message here"></textarea>
</div>
</fieldset>
</div>
</div>
<div class="text-right">
<button type="submit" class="btn btn-primary">Submit form <i class="icon-arrow-right14 position-right"></i></button>
</div>
</div>
</div>
</form>
<!-- Footer -->
<div class="footer text-muted f-xs text-center">
© 2016. ระบบจองรถตู้ออนไลน์ by ออนทัว
</div>
<!-- /footer -->
</div>
</div>
</div>
</div>
<!-- Core JS files -->
<script type="text/javascript" src="assets/js/plugins/loaders/pace.min.js"></script>
<script type="text/javascript" src="assets/js/core/libraries/jquery.min.js"></script>
<script type="text/javascript" src="assets/js/core/libraries/bootstrap.min.js"></script>
<script type="text/javascript" src="assets/js/plugins/loaders/blockui.min.js"></script>
<!-- /core JS files -->
<script type="text/javascript" src="assets/js/core/libraries/jquery_ui/interactions.min.js"></script>
<script type="text/javascript" src="assets/js/plugins/forms/selects/select2.min.js"></script>
<script type="text/javascript" src="assets/js/pages/form_select2.js"></script>
<script type="text/javascript" src="assets/js/plugins/forms/styling/uniform.min.js"></script>
<script type="text/javascript" src="assets/js/core/app.js"></script>
<script type="text/javascript" src="assets/js/pages/form_layouts.js"></script>
<script type="text/javascript" src="assets/js/plugins/forms/styling/uniform.min.js"></script>
<script type="text/javascript" src="assets/js/plugins/forms/styling/switchery.min.js"></script>
<script type="text/javascript" src="assets/js/plugins/forms/styling/switch.min.js"></script>
<script type="text/javascript" src="assets/js/pages/form_checkboxes_radios.js"></script>
</table>
</body>
</html>
This is the only required
<table border="0" width="100%">
<thead>
<tr>
<th>
<div class="row">
<div class="col-md-10">
<div class="form-group">
<label class="display-block text-semibold"> จังหวัดที่ท่องเที่ยว</label>
<select name="province_id[]" id="selProvince" class="select-search">
<option value="">กรุณาเลือกจังหวัด</option>
<?php
include("connect.inc.php");
$SelectPr="SELECT * FROM province";
$QueryPro=mysql_query($SelectPr);
while($Pro=mysql_fetch_array($QueryPro)){
?>
<option value="<?=$Pro['province_id']?>"><?=$Pro['province_name']?></option>
<?php } ?>
</select>
</div>
</div>
</div>
</th>
<th>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label class="display-block text-semibold"> สถานที่ท่องเที่ยว</label>
<select id="selTravel" name="travel_id[]" class="select-search"><option value="">กรุณาเลือกจังหวัด</option></select>
</div>
</div>
</div>
</div>
</th>
<th>
</th>
</tr>
<tr><td><center>รายการที่เพิ่ม</center></td></tr>
</thead>
<tbody>
</tbody>
</table>
<div class="row">
<div class="form-group">
<div class="col-md-6">
<button type="button" id="btnP">เพิ่มรายการ</button>
</div>
</div>
</div>
FORM INSERT
<?php
session_start();
//PUT THIS HEADER ON TOP OF EACH UNIQUE PAGE
if(!isset($_SESSION['id_user'])){
header("location:index.php");
}
include_once('config.php');
$id_user = $_SESSION['id_user'];
$rn_first_name = $_POST['rn_first_name'];
$rn_last_name = $_POST['rn_last_name'];
$rn_gostart = $_POST['rn_gostart'];
$rn_endstart = $_POST['rn_endstart'];
$time_gostart = $_POST['time_gostart'];
$time_endstart = $_POST['time_endstart'];
$rn_tel = $_POST['rn_tel'];
$rn_amount = $_POST['rn_amount'];
$rn_svan = $_POST['rn_svan'];
$rn_destination = $_POST['rn_destination'];
$id_invoice = $_POST['id_invoice'];
$Status = $_POST['Status'];
$vn_dtial = $_POST['vn_dtial'];
$rn_place = $_POST['rn_place'];
$travellist_id = $_POST['travellist_id'];
$province_id = $_POST['province_id'];
$travel_id = $_POST['travel_id'];
$total = $_POST['total'];
// function date
$date_go = "$rn_gostart"; //กำหนดค้นวันที่เริ่ม
$date_end = "$rn_endstart"; //กำหนดค้นวันที่กลับ
$datetime1 = new DateTime($date_go);
$datetime2 = new DateTime($date_end);
$datetotal = $datetime1->diff($datetime2);
$total= $datetotal->format('%a') * 1800; //ผลการคำนวณ
$date = "$rn_gostart"; //กำหนดค้นวันที่
$result = mysqli_query($mysqli,"select * from vn_rent where rn_gostart = '$date'");
$ckd = mysqli_num_rows($result);
if($ckd >= 3){
$msg = "<div class='alert alert-danger'>
<span class='glyphicon glyphicon-info-sign'></span> วันที่จองเต็มแล้ว
</div>";
}else{
// ส่วนของการ insert
$sql = "INSERT INTO vn_rent (id_user,rn_first_name,rn_last_name,rn_gostart,rn_endstart,time_gostart,time_endstart,rn_tel,rn_amount,rn_svan,Status,vn_dtial,rn_place,rn_destination,total)
VALUES ('$id_user', '$rn_first_name',' $rn_last_name ','$rn_gostart','$rn_endstart','$time_gostart','$time_endstart','$rn_tel','$rn_amount','$rn_svan','$Status','$vn_dtial','$rn_place','$rn_destination','$total')";
//คำสั่ง insert 2 ตาราง ที่ส่งค่าไปอีกตารางแล้วนำกลับมาอัปเดท
if ($mysqli->query($sql) === TRUE) {
$id_van = $mysqli->insert_id;
$mysqli->query("INSERT INTO invoice
(id_user,id_van)
VALUE($id_user, $id_van)");
$id_invoice = $mysqli->insert_id;
$mysqli->query("UPDATE vn_rent
SET id_invoice = '$id_invoice'
WHERE id_van = $id_van");
$msg = "<div class ='alert alert-success alert-styled-left alert-arrow-left alert-bordered'>
จองรถตู้สำเร็จ โปรดรอการตอบรับจากทางเจ้าหน้าที่</p> เลขที่รายการจอง <span class='text-warning'>".$id_van."</span> เลขที่ใบเสร็จ <span class='text-warning'>".$id_invoice."</span>
</div>";
header("refresh:5; url=history_booking.php");
}
else {
echo "Error: " . $sql . "<br>" . $mysqli->error;
}
}
$mysqli->close();
?>
To put that into multiple records from select into the table travel_list
multiple records from select
I want to know how to display a user's username inside a textbox. I'm doing this because when they edit their settings and update them, it updates their email etc to blank fields in the database:
Here's the code i'd like to change
<input type="text" name="name" class="form-control" id="name" class="required" value="<? echo $row_settings['full_name']; ?>" />
I'd like to make the `value = $row_settings['full_name'];'
How can i do this?
ALL CODE:
<?php
/********************** MYSETTINGS.PHP**************************
This updates user settings and password
************************************************************/
include 'dbc.php';
page_protect();
$err = array();
$msg = array();
if($_POST['doUpdate'] == 'Update')
{
$rs_pwd = mysql_query("select pwd from users where id='$_SESSION[user_id]'");
list($old) = mysql_fetch_row($rs_pwd);
$old_salt = substr($old,0,9);
//check for old password in md5 format
if($old === PwdHash($_POST['pwd_old'],$old_salt))
{
$newsha1 = PwdHash($_POST['pwd_new']);
mysql_query("update users set pwd='$newsha1' where id='$_SESSION[user_id]'");
$msg[] = "Your new password is updated";
//header("Location: mysettings.php?msg=Your new password is updated");
} else
{
$err[] = "Your old password is invalid";
//header("Location: mysettings.php?msg=Your old password is invalid");
}
}
if($_POST['doSave'] == 'Save')
{
// Filter POST data for harmful code (sanitize)
foreach($_POST as $key => $value) {
$data[$key] = filter($value);
}
mysql_query("UPDATE users SET
`full_name` = '$data[name]',
`address` = '$data[address]',
`tel` = '$data[tel]',
`user_email` = '$data[user_email]',
`user_name` = '$data[user]',
`fax` = '$data[fax]',
`country` = '$data[country]',
`website` = '$data[web]'
WHERE id='$_SESSION[user_id]'
") or die(mysql_error());
//header("Location: mysettings.php?msg=Profile Sucessfully saved");
$msg[] = "Profile Sucessfully saved";
}
$rs_settings = mysql_query("select * from users where id='$_SESSION[user_id]'");
?>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" href="../../assets/ico/favicon.ico">
<script language="JavaScript" type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script language="JavaScript" type="text/javascript" src="js/jquery.validate.js"></script>
<script>
$(document).ready(function(){
$("#myform").validate();
$("#pform").validate();
});
</script>
<title>The Infibox - Edit Profile</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/indexSettings.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<?php if (isset($_SESSION['user_id'])) {?>
<a class="navbar-brand" href="#">Infibox</a>
<a class="navbar-brand">|</a>
<a class="navbar-brand" href="/recruitment">My Account</a>
<a class="navbar-brand" href="#">Settings</a>
<a class="navbar-brand" href="#">Logout</a>
<?php }
?>
<?php
if (checkAdmin()) {
/*******************************END**************************/
?>
<a class="navbar-brand" href="admin.php">Admin CP </a>
<?php } ?>
</div>
<div class="navbar-collapse collapse">
<form class="navbar-form navbar-right" role="form">
<div class="form-group">
<input type="text" placeholder="Email" class="form-control">
</div>
<div class="form-group">
<input type="password" placeholder="Password" class="form-control">
</div>
<button type="submit" class="btn btn-success">Sign in</button>
</form>
</div><!--/.navbar-collapse -->
</div>
</div>
<!-- Main jumbotron for a primary marketing message or call to action -->
<p>
<?php
if(!empty($err)) {
echo "<div class=\"msg\">";
foreach ($err as $e) {
echo "* Error - $e <br>";
}
echo "</div>";
}
if(!empty($msg)) {
echo "<div class=\"msg\">" . $msg[0] . "</div>";
}
?>
</p>
<!-- Show their details inside the correct box. E.g. their first name they registered with will be shown inside the "First Name" box. Does not occur with passwords. -->
<center>
<div class="wrapper">
<h2 class="title">Edit Profile</h2>
<?php while ($row_settings = mysql_fetch_array($rs_settings)) ?>
<form action="mysettings1.php" method="post" name="myform" id="myform">
<div class="input-group" id="fname">
<span class="input-group-addon">Name</span>
<input type="text" name="name" class="form-control" id="name" class="required" value="<? echo $row_settings['full_name']; ?>" />
</div>
<div class="input-group">
<span class="input-group-addon">Customer ID</span>
<input type="text" name="user" class="form-control" maxlength="6" id="web2" value="<? echo $row_settings['user_name']; ?>">
</div>
<div class="input-group">
<span class="input-group-addon">Email</span>
<input type="text" class="form-control" name="user_email" id="web3" value="<? echo $row_settings['user_email']; ?>">
</div>
<div class="input-group">
<span class="input-group-addon">Add Paypal Email</span>
<input type="text" class="form-control" name="tel" id="tel" class="required" value="<? echo $row_settings['tel']; ?>">
</div>
<div class="btn-group">
<input name="doSave" type="submit" id="doSave" value="Save" class="btn btn-success">
</div>
<hr class="hr" />
<!-- When Changing Password Old Password Must Be Entered + Correct-->
<h2 class="title2">Change Password</h2>
<div class="input-group">
<span class="input-group-addon">Old Password</span>
<input type="password" class="form-control" name="pwd_old" class="required password" id="pwd_old" >
</div>
<div class="input-group">
<span class="input-group-addon">New Password</span>
<input type="password" class="form-control" name="pwd_new" class="required password" id="pwd_new" >
</div>
<div class="btn-group">
<input name="doUpdate" type="submit" id="doUpdate" value="Update" class="btn btn-success">
</div>
</div>
</center>
</form>
<!-- ##################################################################################### -->
<!-- ##################################################################################### -->
</div>
</center>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
You do not need a while loop:
Change
<?php while ($row_settings = mysql_fetch_array($rs_settings)) ?>
with
<?php $row_settings = mysql_fetch_array($rs_settings); ?>