TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ijas Hameem
NA
25
7k
how to check if value already exists in mysql database
Jul 18 2017 4:46 AM
when i search a value from text box, i want to check if proname not available in product table want to insert a new data to the table. and also update the stock table and stockrecieve table.i will display my code here
<!DOCTYPE html>
<html lang="en">
<?php include 'header.php'; ?>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<?php include_once 'db.php'; ?>
<?php
$invoice = $_POST['invoice'];
$date = $_POST['invdate'];
$product = $_POST['product'];
$qty = $_POST['quantity'].' '.$_POST['measure'];
$buy = $_POST['buyprice'];
$sell = $_POST['sellprice'];
$sql = "INSERT INTO stockrecieve (invoice, invdate, product_name, qty, buy_price, sellprice) VALUES ('$invoice','$date','$product','$qty','$buy','$sell')";
if ($mysqli->query($sql) === TRUE) {
}
else {
echo "Error: ".$sql."<br>".$mysqli->error;
}
$sql1 = "INSERT INTO stock (st_date, procode, sellprice, quantity) VALUES ('$date','$product','$sell','$qty')";
if ($mysqli->query($sql1)=== TRUE){
echo "<script> alert('Successfully Executed'); </script>";
}
}
?>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<div class="header-icon">
<i class="fa fa-cart-arrow-down"></i>
</div>
<div class="header-title">
<h1>Add Stock</h1>
<small>Add new Stock & View Stock</small>
</div>
</section>
<!-- Main content -->
<section class="content">
<div class="row">
<div class="col-sm-4">
<div class="panel lobidisable panel-bd">
<div class="panel-heading">
<div class="panel-title">
<h4>Add Stock</h4>
</div>
</div>
<form method="POST">
<div class="panel-body">
<div class="form-group">
<label>Invoice Number</label>
<input type="text" class="form-control" placeholder="Invoice Number" name="invoice" required>
</div>
<div>
<label>Find Product Name</label>
<input type="text" name="product" id="productname" class="form-control" placeholder="Enter Product Name" />
<div id="productList"></div>
<div class="form-group">
</div>
<div class="row">
<div class="col-sm-8">
<label>Measure Qty</label>
<input type="number" name="quantity" class=" form-control" placeholder="Enter Quantity"></div>
<div class="col-sm-4"><label>Metric Unit</label>
<select name="measure" class="form-control">
<option value=" " >Select..</option>
<option value="Peices">Peices</option>
<option value="g">g</option>
<option value="kg">Kg</option>
<option value="mg">mg</option>
<option value="ltr">ltr</option>
</select></div>
</div>
<label>Date</label>
<div class=" input-group date form_date">
<input type="date" class="form-control years" name="invdate"><span class="input-group-addon"><a href="#"><i class="fa fa-calendar"></i></a></span>
</div>
</div>
<div class="form-group">
<label>Buying Price</label>
<input type="float" class="form-control" placeholder="Enter Buying Price " name="buyprice" >
</div>
<div class="form-group">
<label>Selling Price</label>
<input type="float" name="sellprice" class="form-control" placeholder="Enter Selling Price" >
</div>
<div class="form-group">
<span class="btn btn-add"><i class="fa fa-check">
<input type="submit" name="save" class="btn btn-add"></i></span>
</div>
</form>
</div>
</div>
</div>
</div>
</section>
<!-- /.content -->
</div>
<!-- /.content-wrapper -->
<?php include 'footer.php'; ?>
</div>
<!-- ./wrapper -->
<!-- Start Core Plugins
=====================================================================-->
<!-- Slelect 2 -->
<!-- jQuery -->
<script src="assets/plugins/jQuery/jquery-1.12.4.min.js" type="text/javascript"></script>
<!-- jquery-ui -->
<script src="assets/plugins/jquery-ui-1.12.1/jquery-ui.min.js" type="text/javascript"></script>
<!-- Bootstrap -->
<script src="assets/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<!-- lobipanel -->
<script src="assets/plugins/lobipanel/lobipanel.min.js" type="text/javascript"></script>
<!-- Pace js -->
<script src="assets/plugins/pace/pace.min.js" type="text/javascript"></script>
<!-- SlimScroll -->
<script src="assets/plugins/slimScroll/jquery.slimscroll.min.js" type="text/javascript"></script>
<!-- FastClick -->
<script src="assets/plugins/fastclick/fastclick.min.js" type="text/javascript"></script>
<!-- CRMadmin frame -->
<script src="assets/dist/js/custom.js" type="text/javascript"></script>
<!-- End Core Plugins
=====================================================================-->
<!-- Start Theme label Script
=====================================================================-->
<!-- Dashboard js -->
<script src="assets/dist/js/dashboard.js" type="text/javascript"></script>
<!-- End Theme label Script
=====================================================================-->
</body>
</html>
<script>
$(document).ready(function(){
$('#productname').keyup(function(){
var val = $('#productname').val();
if(val.length==0){
$('#productList').html('');
}
var query = $(this).val();
if(query != '')
{
$.ajax({
url:"search.php",
method:"POST",
data:{query:query},
success:function(data)
{
$('#productList').fadeIn();
$('#productList').html(data);
}
});
}
});
$(document).on('click', 'li', function(){
$('#productname').val($(this).text());
$('#productList').fadeOut();
});
});
</script>
Reply
Answers (
1
)
Provide some Resources to learn Laravel PHP ?
MySql Lock wait timeout exceeded; try restarting transaction