แก้error Undefined index แล้วเกิดerror You have an error in your SQL syntax;
Error
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ' std_id='', std_prefix ='', std_name ='', std_lastname ='', WHERE std_id = ' at line 1
Code (PHP)
<?php
include 'connect.php';
$studentid=isset($_POST['studentid']) ? $_POST['studentid']:'';
$studentprefix=isset($_POST['studentprefix']) ? $_POST['studentprefix']:'';
$studentname=isset($_POST['studentname']) ? $_POST['studentname']:'';
$studentlastname=isset($_POST['studentlastname']) ? $_POST['studentlastname']:'';
$strSQL = "UPDATE student SET,
std_id='".mysql_real_escape_string($studentid)."',
std_prefix ='".mysql_real_escape_string($studentprefix)."',
std_name ='".mysql_real_escape_string($studentname)."',
std_lastname ='".mysql_real_escape_string($studentlastname)."',
WHERE std_id = '".mysql_real_escape_string($studentid)."'";
$objQuery = mysql_query($strSQL)or die (mysql_error());
mysql_query("SET NAME UTF8, $connect");
if($objQuery)
{
echo "Edit Infomation Success.";
echo "<script>window.location='searchstd.php'</script>";
}
else
{
echo "Error Save [".$strSQL."]";
}
mysql_close($connect);
?>
<!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></title>
<!-- CSS -->
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Roboto:400,100,300,500">
<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="assets/css/form-elements.css">
<link rel="stylesheet" href="assets/css/style.css">
<!-- HTML5 Shim and Respond.js 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/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>
<!-- Top content -->
<div class="row">
<div class="col-sm-6 col-sm-offset-3 form-box">
<div class="form-top">
<div class="form-top-left">
<h3>Student Information</h3>
<p>Edit Student Information :</p>
</div>
<div class="form-top-right">
<i class="fa fa-user"></i>
</div>
</div>
<div class="form-bottom">
<form role="form" action="editstd.php" method="post" class="student">
<div class="form-group">
<label class="sr-only" for="form-studentid">StudentID.</label>
<input type="text" name="studentid" placeholder="ID..." class="form-studentid form-control" id="studentid">
</div>
<div class="col-xs-6 col-md-4">
<div class="radio">
<label >
<input type="radio" name="studentprefix" id="optionsRadios1" value="Mr." checked>
Mr.
</label>
</div>
</div>
<div class="col-xs-6 col-md-4">
<div class="radio">
<label class="radio-inline">
<input type="radio" name="studentprefix" id="optionsRadios2" value="Mrs.">
Mrs.
</label>
</div>
</div>
<div class="col-xs-6 col-md-4">
<div class="radio">
<label class="radio-inline">
<input type="radio" name="studentprefix" id="optionsRadios2" value="Ms.">
Miss.
</label>
</div>
</div>
<div class="form-group">
<label class="sr-only" for="form-name">Name</label>
<input type="text" name="studentname" placeholder="Name..." class="form-studentname form-control" id="name">
</div>
<div class="form-group">
<label class="sr-only" for="form-lastname">Lastname</label>
<input type="text" name="studentlastname" placeholder="Lastname..." class="form-studentlastname form-control" id="lastname">
</div>
<div class="row">
<div class="col-xs-6 col-md-4">
<button type="submit" class="btn btn-info" value="submit">Save</button></div>
<div class="col-xs-6 col-md-4">
<button type="reset" class="btn btn-warning" value="reset">Cancel</button></div>
<div class="col-xs-6 col-md-4">
<button type="reset" class="btn btn-danger" value="canecl" onclick="window.location='searchstd.php';">Back</button></div>
</div>
</div>
</form>
</div>
</div>
</div>
<!-- Javascript -->
<script src="assets/js/jquery-1.11.1.min.js"></script>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/js/jquery.backstretch.min.js"></script>
<script src="assets/js/scripts.js"></script>
<!--[if lt IE 10]>
<script src="assets/js/placeholder.js"> </script>
<![endif]-->
</body>
</html>
Tag : PHP, MySQL, HTML/CSS, JavaScript, Windows, Web Service
Date :
2016-05-03 16:50:34
By :
Laf
View :
841
Reply :
3
std_id='', std_prefix ='', std_name ='', std_lastname ='', WHERE std_id
ลูกน้ำเกินมาตัวหนึงครับ
ประวัติการแก้ไข 2016-05-03 17:07:01 2016-05-03 17:07:34
Date :
2016-05-03 17:06:39
By :
ALTELMA
https://www.thaicreate.com/php.html
https://www.thaicreate.com/php/php-mysql-update-edit-record.html
ที่นี่มีทุกอย่างครับ ลองเริ่มศึกษาเลยๆๆๆ
Date :
2016-05-03 21:41:28
By :
ALTELMA
Load balance : Server 03