|
|
|
กด edit มันจะขึ้นมาหมดเลยในฐานข้อมูล และแก้ไขได้เฉพาะล่างสุด |
|
|
|
|
|
|
|
<?php
require('connect.php');
require('menu.php');
?>
<html>
<head>
<title>nOva</title>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body>
<?php
global $con;
//*** Add Condition ***//
if(isset($_POST['hdnCmd']) && $_POST['hdnCmd']== "Add")
{
$strSQL = "INSERT INTO nova_type ";
$strSQL .="(type_id,type_code,type_name) ";
$strSQL .="VALUES ";
$strSQL .="('','".$_POST["type_code"]."','".$_POST["type_name"]."' ) ";
$objQuery = mysqli_query($con, $strSQL) or die('Could not look up user information; ' . mysqli_error());
//header("location:$_SERVER[PHP_SELF]");
//exit();
}
//*** Update Condition ***//
if(isset($_POST['hdnCmd']) && $_POST['hdnCmd'] == "Update")
{
$strSQL = "UPDATE nova_type SET ";
$strSQL .="type_id = '".$_POST["type_id"]."' ";
$strSQL .=",type_code = '".$_POST["type_code"]."' ";
$strSQL .=",type_name = '".$_POST["type_name"]."' ";
$strSQL .="WHERE type_id = '".$_POST["type_id"]."' ";
$objQuery = mysqli_query($con, $strSQL);
if(!$objQuery)
{
echo "Error Update [". mysqli_error()."]";
}
}
//*** Delete Condition ***//
if(isset($_GET['Action']) && $_GET['Action'] == "Del")
{
$strSQL = " DELETE FROM nova_type ";
$strSQL .=" WHERE type_id = '".$_GET['type_id']."' ";
$objQuery = mysqli_query($con, $strSQL);
if(!$objQuery)
{
echo "Error Delete [". mysqli_error()."]";
}
}
$strSQL = "SELECT * FROM nova_type";
$objQuery = mysqli_query($con, $strSQL) or die ("Error Query [".$strSQL."]");
?>
<form name="frmMain" method="post" action="<?php echo $_SERVER["PHP_SELF"];?>">
<input type="hidden" name="hdnCmd" value="">
<table width="600" border="0" align="center" class="table" valign="middle">
<tr>
<p>
<td height="45" colspan="5">
<button type="button" class="btn btn-success" data-toggle="modal" data-target="#exampleModal" data-whatever="@getbootstrap">ADD PRODUCT</button>
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">NEW PRODUCT</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<label for="recipient-name" class="col-form-label">PRODUCT CODE:</label>
<input type="text" class="form-control" id="type_code" name="type_code">
</div>
<div class="form-group">
<label for="message-text" class="col-form-label">PRODUCT NAME:</label>
<input type="text" class="form-control" id="type_code" name="type_name">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
<button name="btnAdd" type="button" id="btnAdd" value="Add"
OnClick="frmMain.hdnCmd.value='Add';frmMain.submit();" class="btn btn-success">Save</button>
</div>
</div>
</div>
</div>
</td>
</tr>
<tr>
<td align="center">#</td>
<td>PRODUCT CODE</td>
<td>PRODUCT NAME</td>
<td></td>
<td></td>
</tr>
<?php
while($objResult = mysqli_fetch_array($objQuery))
{
?>
<?php
$strAction = isset($_GET['Action']) ? $_GET['Action'] : '';
if($strAction == "Edit")
{
if($objResult["type_id"] == $_GET["type_id"] && $_GET["Action"] == "Edit")
{
}
?>
<tr>
<td><input type="text" name="type_id" value="<?php echo $objResult["type_id"];?>"></td>
<td><input type="text" name="type_code" value="<?php echo $objResult["type_code"];?>"></td>
<td><input type="text" name="type_name" value="<?php echo $objResult["type_name"];?>"></td>
<td colspan="2" align="right">
<div align="center">
<input name="btnAdd" type="button" id="btnUpdate" value="Update" OnClick="frmMain.hdnCmd.value='Update';frmMain.submit();">
<input name="btnAdd" type="button" id="btnCancel" value="Cancel" OnClick="window.location='<?php echo $_SERVER["PHP_SELF"];?>';">
</div>
</td>
</tr>
<?php
}
else
{
?>
<tr>
<td align="center"><div align="center"><?php echo $objResult["type_id"];?></div></td>
<td><?php echo $objResult["type_code"];?></td>
<td><?php echo $objResult["type_name"];?></td>
<td align="center">
<button type="button" class="btn btn-success" data-toggle="modal" data-target="#myModal" data-whatever="@getbootstrap"><a href="<?php echo $_SERVER["PHP_SELF"];?>?Action=Edit&type_id=<?php echo $objResult["type_id"];?>">Edit</a></button>
<button type="button" class="btn btn-danger" data-dismiss="modal"><a href="JavaScript:if(confirm('Confirm Delete?')==true){window.location='<?php echo $_SERVER["PHP_SELF"];?>?Action=Del&type_id=<?php echo $objResult["type_id"];?>';}">Delete</a></button>
</td>
</tr>
</tr>
<?php
}
?>
<?php
}
?>
</table>
</form>
<?php
mysqli_close($con);
?>
</body>
</html>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2018-07-11 11:47:06 |
By :
10209228904480129 |
View :
1121 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ใส่ tag ดีกว่านะครับ จะได้ดูง่าย
Code (PHP)
<?php
require('connect.php');
require('menu.php');
?>
<html>
<head>
<title>nOva</title>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body>
<?php
global $con;
//*** Add Condition ***//
if(isset($_POST['hdnCmd']) && $_POST['hdnCmd']== "Add")
{
$strSQL = "INSERT INTO nova_type ";
$strSQL .="(type_id,type_code,type_name) ";
$strSQL .="VALUES ";
$strSQL .="('','".$_POST["type_code"]."','".$_POST["type_name"]."' ) ";
$objQuery = mysqli_query($con, $strSQL) or die('Could not look up user information; ' . mysqli_error());
//header("location:$_SERVER[PHP_SELF]");
//exit();
}
//*** Update Condition ***//
if(isset($_POST['hdnCmd']) && $_POST['hdnCmd'] == "Update")
{
$strSQL = "UPDATE nova_type SET ";
$strSQL .="type_id = '".$_POST["type_id"]."' ";
$strSQL .=",type_code = '".$_POST["type_code"]."' ";
$strSQL .=",type_name = '".$_POST["type_name"]."' ";
$strSQL .="WHERE type_id = '".$_POST["type_id"]."' ";
$objQuery = mysqli_query($con, $strSQL);
if(!$objQuery)
{
echo "Error Update [". mysqli_error()."]";
}
}
//*** Delete Condition ***//
if(isset($_GET['Action']) && $_GET['Action'] == "Del")
{
$strSQL = " DELETE FROM nova_type ";
$strSQL .=" WHERE type_id = '".$_GET['type_id']."' ";
$objQuery = mysqli_query($con, $strSQL);
if(!$objQuery)
{
echo "Error Delete [". mysqli_error()."]";
}
}
$strSQL = "SELECT * FROM nova_type";
$objQuery = mysqli_query($con, $strSQL) or die ("Error Query [".$strSQL."]");
?>
<form name="frmMain" method="post" action="<?php echo $_SERVER["PHP_SELF"];?>">
<input type="hidden" name="hdnCmd" value="">
<table width="600" border="0" align="center" class="table" valign="middle">
<tr>
<p>
<td height="45" colspan="5">
<button type="button" class="btn btn-success" data-toggle="modal" data-target="#exampleModal" data-whatever="@getbootstrap">ADD PRODUCT</button>
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">NEW PRODUCT</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<label for="recipient-name" class="col-form-label">PRODUCT CODE:</label>
<input type="text" class="form-control" id="type_code" name="type_code">
</div>
<div class="form-group">
<label for="message-text" class="col-form-label">PRODUCT NAME:</label>
<input type="text" class="form-control" id="type_code" name="type_name">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
<button name="btnAdd" type="button" id="btnAdd" value="Add"
OnClick="frmMain.hdnCmd.value='Add';frmMain.submit();" class="btn btn-success">Save</button>
</div>
</div>
</div>
</div>
</td>
</tr>
<tr>
<td align="center">#</td>
<td>PRODUCT CODE</td>
<td>PRODUCT NAME</td>
<td></td>
<td></td>
</tr>
<?php
while($objResult = mysqli_fetch_array($objQuery))
{
?>
<?php
$strAction = isset($_GET['Action']) ? $_GET['Action'] : '';
if($strAction == "Edit")
{
if($objResult["type_id"] == $_GET["type_id"] && $_GET["Action"] == "Edit")
{
}
?>
<tr>
<td><input type="text" name="type_id" value="<?php echo $objResult["type_id"];?>"></td>
<td><input type="text" name="type_code" value="<?php echo $objResult["type_code"];?>"></td>
<td><input type="text" name="type_name" value="<?php echo $objResult["type_name"];?>"></td>
<td colspan="2" align="right">
<div align="center">
<input name="btnAdd" type="button" id="btnUpdate" value="Update" OnClick="frmMain.hdnCmd.value='Update';frmMain.submit();">
<input name="btnAdd" type="button" id="btnCancel" value="Cancel" OnClick="window.location='<?php echo $_SERVER["PHP_SELF"];?>';">
</div>
</td>
</tr>
<?php
}
else
{
?>
<tr>
<td align="center"><div align="center"><?php echo $objResult["type_id"];?></div></td>
<td><?php echo $objResult["type_code"];?></td>
<td><?php echo $objResult["type_name"];?></td>
<td align="center">
<button type="button" class="btn btn-success" data-toggle="modal" data-target="#myModal" data-whatever="@getbootstrap"><a href="<?php echo $_SERVER["PHP_SELF"];?>?Action=Edit&type_id=<?php echo $objResult["type_id"];?>">Edit</a></button>
<button type="button" class="btn btn-danger" data-dismiss="modal"><a href="JavaScript:if(confirm('Confirm Delete?')==true){window.location='<?php echo $_SERVER["PHP_SELF"];?>?Action=Del&type_id=<?php echo $objResult["type_id"];?>';}">Delete</a></button>
</td>
</tr>
</tr>
<?php
}
?>
<?php
}
?>
</table>
</form>
<?php
mysqli_close($con);
?>
</body>
</html>
|
|
|
|
|
Date :
2018-07-11 14:01:28 |
By :
mongkon.k |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|