ฟอร์มแก้ไขข้อมูลใน db ค่าเก่าไม่ขึ้นครับ "Not found PartID" ครับ
Code ที่โพสต์มาให้ดูนี่ อยู่เพจเดียวกัน หรือ คนละเพจครับ
ที่มันแสดง Not found PartID ก็เพราะ
if(!$objResult)
{
echo "Not found PartID=".$_GET["PartID"];
}
ต้องตีโจทย์การคิวรี่ก่อนหน้าบรรทัดนี่ว่าต้องการอะไร
แล้วอีกกรณีค่า $_GET["PartID"]; ส่งค่านี้มาจากฟอร์มไหนครับ
ค่าถูกส่งมาจากไหม
ในบรรทัดแรกสุด ลอง echo ค่าตัวแปรออกมาดูว่า ค่าถูกส่งมาจริงไหม
จากนั้น echo $strSQL; ว่ารูปแบบมันถูกต้องไหม ลองเอาไปรันใน phpMyadmin ก็ได้ครับ
ผลรับได้ตามต้องการไหม
ประวัติการแก้ไข 2015-02-03 14:18:11
Date :
2015-02-03 14:17:00
By :
apisitp
ตอบความคิดเห็นที่ : 1 เขียนโดย : apisitp เมื่อวันที่ 2015-02-03 14:17:00
รายละเอียดของการตอบ ::
คนละเพจครับ
อันนี้อีกเพจครับ
Code
<!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">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="sep.ico">
<title>Dashboard Template for Bootstrap</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="dashboard.css" rel="stylesheet">
<!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
<!--[if lt IE 9]><script src="assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
<script src="assets/js/ie-emulation-modes-warning.js"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[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 style="
h1, h2, h3, h4, h5, h6 {
font-family:'MS Sans Serif';
}
p, div {
font-family:'MS Sans Serif';
}
" >
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Project name</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Dashboard</a></li>
<li><a href="#">Settings</a></li>
<li><a href="#">Profile</a></li>
<li><a href="#">Help</a></li>
</ul>
<form class="navbar-form navbar-right">
<input type="text" class="form-control" placeholder="Search...">
</form>
</div>
</div>
</nav>
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 col-md-2 sidebar">
<ul class="nav nav-sidebar">
<li ><a href="index.php">ข้อมูล<span class="sr-only">(current)</span></a></li>
<li><a href="new.php">เพิ่ม<span class="sr-only">(current)</span></a></li>
<li class="active" ><a href="edit.php">แก้ไข<span class="sr-only">(current)</span></a></li>
<li ><a href="delete.php">ลบ<span class="sr-only">(current)</span></a></li>
<li><a href="#">ทดสอบ<span class="sr-only">(current)</span></a></li>
</ul>
</div>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<H2 class="sub-header">แก้ไขข้อมูล</H2>
<form action="phpMySQLEditRecordSave.php?CusID=<?php echo $_GET["PartID"];?>" name="frmEdit" method="post">
<?php
$servername = "localhost";
$username = "root";
$password = "admin";
$dbname = "inventory";
?>
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>รหัส</th>
<th>code</th>
<th>ชื่อ</th>
<th>รุ่น</th>
<th>จำนวน</th>
<th>line ผลิต</th>
<th>S/n</th>
<th>หมายเหตุ</th>
</tr>
</thead>
<tbody>
<?
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM machinemaster";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
?>
<tr>
<td><? echo $row['PartID'] ?></td>
<td><? echo $row['Partcode'] ?></td>
<td><? echo $row['PartType'] ?></td>
<td><? echo $row['partname'] ?></td>
<td><? echo $row['partModel'] ?></td>
<td><? echo $row['PartQTY'] ?></td>
<td><? echo $row['partdate'] ?></td>
<td><? echo $row['PartR'] ?></td>
<td align="center"><a href="EditForm.php?PartID=<?php echo $objResult["PartID"];?>">Edit</a>
</td>
</tr>
<?
}
} else {
echo "0 results";
}
$conn->close();
?>
</tbody>
</table>
</div>
<!-- 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.1/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="assets/js/docs.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="assets/js/ie10-viewport-bug-workaround.js"></script>
</body>
</html>
Date :
2015-02-03 14:24:29
By :
Nerazzurri
อันนี้โค้ดหน้าแรกครับ
Code (PHP)
<!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">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="sep.ico">
<title>Dashboard Template for Bootstrap</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="dashboard.css" rel="stylesheet">
<!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
<!--[if lt IE 9]><script src="assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
<script src="assets/js/ie-emulation-modes-warning.js"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[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 style="
h1, h2, h3, h4, h5, h6 {
font-family:'MS Sans Serif';
}
p, div {
font-family:'MS Sans Serif';
}
" >
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Project name</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Dashboard</a></li>
<li><a href="#">Settings</a></li>
<li><a href="#">Profile</a></li>
<li><a href="#">Help</a></li>
</ul>
<form class="navbar-form navbar-right">
<input type="text" class="form-control" placeholder="Search...">
</form>
</div>
</div>
</nav>
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 col-md-2 sidebar">
<ul class="nav nav-sidebar">
<li ><a href="index.php">ข้อมูล<span class="sr-only">(current)</span></a></li>
<li><a href="new.php">เพิ่ม<span class="sr-only">(current)</span></a></li>
<li class="active" ><a href="edit.php">แก้ไข<span class="sr-only">(current)</span></a></li>
<li ><a href="delete.php">ลบ<span class="sr-only">(current)</span></a></li>
<li><a href="#">ทดสอบ<span class="sr-only">(current)</span></a></li>
</ul>
</div>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<H2 class="sub-header">แก้ไขข้อมูล</H2>
<form action="EditForm.php?PartID=<?php echo $_GET["PartID"];?>" name="frmEdit" method="post">
<?php
$servername = "localhost";
$username = "root";
$password = "admin";
$dbname = "inventory";
?>
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>รหัส</th>
<th>code</th>
<th>ชื่อ</th>
<th>รุ่น</th>
<th>จำนวน</th>
<th>line ผลิต</th>
<th>S/n</th>
<th>หมายเหตุ</th>
</tr>
</thead>
<tbody>
<?
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM machinemaster";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
?>
<tr>
<td><? echo $row['PartID'] ?></td>
<td><? echo $row['Partcode'] ?></td>
<td><? echo $row['PartType'] ?></td>
<td><? echo $row['partname'] ?></td>
<td><? echo $row['partModel'] ?></td>
<td><? echo $row['PartQTY'] ?></td>
<td><? echo $row['partdate'] ?></td>
<td><? echo $row['PartR'] ?></td>
<td align="center"><a href="EditForm.php?PartID=<?php echo $objResult["PartID"];?>">Edit</a>
</td>
</tr>
<?
}
} else {
echo "0 results";
}
$conn->close();
?>
</tbody>
</table>
</div>
<!-- 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.1/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="assets/js/docs.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="assets/js/ie10-viewport-bug-workaround.js"></script>
</body>
</html>
อันนี้หน้าถัดมาครับ
Code (PHP)
<!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">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="sep.ico">
<title>Dashboard Template for Bootstrap</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="dashboard.css" rel="stylesheet">
<!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
<!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
<script src="assets/js/ie-emulation-modes-warning.js"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[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 style="
h1, h2, h3, h4, h5, h6 {
font-family:'MS Sans Serif';
}
p, div {
font-family:'MS Sans Serif';
}
" >
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Project name</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Dashboard</a></li>
<li><a href="#">Settings</a></li>
<li><a href="#">Profile</a></li>
<li><a href="#">Help</a></li>
</ul>
<form class="navbar-form navbar-right">
<input type="text" class="form-control" placeholder="Search...">
</form>
</div>
</div>
</nav>
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 col-md-2 sidebar">
<ul class="nav nav-sidebar">
<li><a href="index.php">ข้อมูล<span class="sr-only">(current)</span></a></li>
<li><a href="new.php">เพิ่ม<span class="sr-only">(current)</span></a></li>
<li class="active"><a href="editform.php">แก้ไข<span class="sr-only">(current)</span></a></li>
<li><a href="delete.php">ลบ<span class="sr-only">(current)</span></a></li>
<li><a href="#">ทดสอบ<span class="sr-only">(current)</span></a></li>
</ul>
</div>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<H2>แก้ไขข้อมูล</H2>
<html>
<head>
<title></title>
<body>
<tr></tr>
<form action="phpEditSave.php?PartID=<?php echo $_GET["PartID"];?>" name="frmEdit" method="post">
<?php
$objConnect = mysql_connect("localhost","root","admin") or die("Error Connect to Database");
$objDB = mysql_select_db("inventory");
$strSQL = "SELECT * FROM machinemaster WHERE PartID = '".$_GET["PartID"]."' ";
$objQuery = mysql_query($strSQL)or die(mysql_error()."[$strSQL]");
$objResult = mysql_fetch_array($objQuery);
if(!$objQuery)
{
echo "Not found PartID=".$_GET["PartID"];
}
else
{
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">PartID</div></th>
<th width="160"> <div align="center">Partcode</div></th>
<th width="198"> <div align="center">PartType</div></th>
<th width="97"> <div align="center">partname</div></th>
<th width="70"> <div align="center">partModel</div></th>
<th width="70"> <div align="center">PartQTY</div></th>
</tr>
<tr>
<td><div align="center"><input type="text" name="txtPartID" size="10" value="
<?php echo
$objResult["PartID"]; ?>"></div></td>
<td><input type="text" name="txtPartcode" size="20" value="<?php echo $objResult["Partcode"];?>"></td>
<td align="right"><input type="text" name="txtPartType" size="20" value="<?php echo $objResult["PartType"];?>"></td>
<td><div align="center"><input type="text" name="txtpartname" size="2" value="<?php echo $objResult["partname"];?>"></div></td>
<td align="right"><input type="text" name="txtpartModel" size="5" value="<?php echo $objResult["partModel"];?>"></td>
<td align="right"><input type="text" name="txtPartQTY" size="5" value="<?php echo $objResult["PartQTY"];?>"></td>
</tr>
</table>
<input type="submit" name="submit" value="submit">
<?php
}
mysql_close($objConnect);
?>
</form>
</body></html>
Date :
2015-02-03 14:57:54
By :
Nerazzurri
Load balance : Server 00