php_billing/119/bill.php

110 lines
3.6 KiB
PHP

<?php
if(isset($_POST['phone'])){
$link = new mysqli(MYSQL_HOST,MYSQL_USER,MYSQL_PASS,MYSQL_DB);
$link->set_charset("utf8");
$query="INSERT INTO `".SHOP_ID."_customer` ( `phone`,`name`,`address`)VALUES(?,?,?)";
$stmt = $link->prepare($query);
if($stmt){
$stmt->bind_param("sss", $_POST['phone'],$_POST['name'],$_POST['address'] );
//if(!$stmt->execute()) echo '<div class="alert alert-danger">' . mysqli_error($link) . '</div>';
if(!$stmt->execute()) echo '<div class="alert alert-danger">' . mysqli_error($link) . '</div>';
else {
echo '<div class="alert alert-success"> customer: '.$_POST['name'].' added</div> <br>
<form method="POST" action="create_bill">
<label for="">Mobile :
<input type="number" name="phone" value="'.$_POST['phone'].'" readonly />
</label> <br> <br>
<label for="">Name :
<input type="text" name="name" value="'.$_POST['name'].'" readonly />
</label><br><br>
<label for="">Address :
<input type="text" name="address" value="'.$_POST['address'].'" readonly />
</label>
<input type="submit" value="Bill" />
</form>
';
// <meta http-equiv="refresh" content="0; url=create_bill?phone='.$_POST['phone'].'">.
}
}
else echo mysqli_error($link);
$link->close();
}
if(isset($_GET['phone'])){
if($_GET['phone']==""){
echo '<form method="POST" action="create_bill" name="start_bill"> <input type="number" name="phone" value="0" /> </form> <script> document.forms["start_bill"].submit(); </script>';
}
else {
$link = new mysqli(MYSQL_HOST,MYSQL_USER,MYSQL_PASS,MYSQL_DB);
$query="SELECT * FROM `".SHOP_ID."_customer` WHERE `phone`='".$_GET['phone']."'";
$result= mysqli_query($link, $query);
if(mysqli_num_rows($result)<1){
echo 'New Customer: <br />
<form method="POST" action="bill">
<label for="">Mobile :
<input type="number" name="phone" value="'.$_GET['phone'].'" />
</label> <br> <br>
<label for="">Name :
<input type="text" name="name" />
</label><br><br>
<label for="">Address :
<input type="text" name="address" />
</label>
<input type="submit" />
</form>
';
}
else {
$row = $result -> fetch_array(MYSQLI_ASSOC);
// var_dump($row);
echo 'New Customer: <br />
<form method="POST" action="create_bill">
<label for="">Mobile :
<input type="number" name="phone" value="'.$row['phone'].'" readonly />
</label> <br> <br>
<label for="">Name :
<input type="text" name="name" value="'.$row['name'].'" readonly />
</label><br><br>
<label for="">Address :
<input type="text" name="address" value="'.$row['address'].'" readonly />
</label>
<input type="submit" value="bill" />
</form>
';
}
echo '
<br><br>
';
}
}
else {
?>
<?php
// else {
?>
<br><br>
<form>
Mobile : <input type="number" name="phone" />
<input type="submit" />
</form>
<!-- <label for="">Mobile :
<input type="number" name="phone" />
</label> <br> <br>
<label for="">Name :
<input type="text" name="name" />
</label><br><br>
<label for="">Address :
<input type="text" name="address" />
</label> -->
<?php
}
?>