我需要更新学生信息。 当我从学生视图页面单击编辑按钮时,它正确显示/检索用户信息。但是当我点击更新/保存后,编辑显示/显示图形错误。 这是我的数据库。
这是edit.php
<?php
session_start();
if(isset($_SESSION['admin'])){
echo "";
}
else
{
header("location:logout.php");
}
require('dbcon.php');
$hjd=$_GET['s_id'];
/* getting link id from index page*/
$que = "SELECT * FROM stu_info WHERE s_id='".$_GET['s_id']."'"; /*selecting id from database*/
$resu = mysqli_query($conl, $que) or die ( mysqli_error());
$rlk = mysqli_fetch_assoc($resu);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>
Edit Profile
</title>
<link rel="stylesheet" href="css/bootstrap.css" />
<script src="js/jquery.min.js">
</script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js">
</script>
<script src="date_picker/datetimepicker_css.js">
</script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form class="form-horizontal" method="GET" action="edit_action.php">
<input type="hidden" name="new" value="1" />
<input type="text" name="chk" value="<?php echo $rlk['s_id']; ?>" hidden="" />
<fieldset>
<!-- Form Name -->
<legend>
Add Student
</legend>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="f_name">
First Name
</label>
<div class="col-md-4">
<input id="f_name" name="f_name" type="text" value="<?php echo $rlk['f_name'];?> " class="form-control input-md" required="">
<span class="help-block">
Student Name
</span>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="l_name">
Last Name
</label>
<div class="col-md-4">
<input id="l_name" name="l_name" type="text" value="<?php echo $rlk['l_name'];?>" class="form-control input-md" required="">
<span class="help-block">
Maybe Father Name
</span>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="roll_no">
Roll No
</label>
<div class="col-md-4">
<input id="roll_no" name="roll_no" type="number" value="<?php echo $rlk['Roll_no'];?>" value="3215" class="form-control input-md" required="">
<span class="help-block">
Student Roll Number
</span>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="dob">
Date Of Birth
</label>
<div class="col-md-4">
<input id="demo1" name="dob" type="text" value="<?php echo $rlk['dob'];?>" class="form-control input-md" required="" onclick="javascript:NewCssCal ('demo1','yyyyMMdd','','','','','')" style="cursor:pointer"/>
<span class="help-block">
Date Of Birth
</span>
</div>
</div>
<!-- Select Basic -->
<div class="form-group">
<label class="col-md-4 control-label" for="cls">
Select Class
</label>
<div class="col-md-4">
<select id="cls" name="cls" class="form-control">
<option value="1">
class 1
</option>
<option value="2">
class 2
</option>
<option value="3">
class 3
</option>
<option value="4">
class 4
</option>
<option value="5">
class 5
</option>
</select>
</div>
</div>
<!-- Select Basic -->
<div class="form-group">
<label class="col-md-4 control-label" for="Gender">
Select Gender
</label>
<div class="col-md-4">
<select id="gender" name="gender" class="form-control">
<option value="male">
male
</option>
<option value="femala">
female
</option>
</select>
</div>
</div>
<!-- Select Basic -->
<div class="form-group">
<label class="col-md-4 control-label" for="reli">
Religion
</label>
<div class="col-md-4">
<select id="reli" name="reli" class="form-control">
<option value="Hindhu">
Hindhu
</option>
<option value="Christian">
Christian
</option>
<option value="Muslim">
Muslim
</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="reli">
Community
</label>
<div class="col-md-4">
<select id="commu" name="commu" class="form-control">
<option value="OC">
OC
</option>
<option value="BC" >
BC
</option>
<option value="MBC">
MBC
</option>
<option value="SC">
SC
</option>
<option value="ST">
ST
</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="reli">
Blood Group
</label>
<div class="col-md-4">
<select id="blg" name="blg" class="form-control">
<option value="A Possitive">
A Possitive
</option>
<option value="A Negative" >
A Negative
</option>
<option value="A1 Possitive">
A1 Possitive
</option>
<option value="A1 Negative">
A1-
</option>
<option value="A1B Possitive">
A1B Possitive
</option>
<option value="A1B Negative">
A1B Negative
</option>
<option value="A2 Possitive">
A2 Possitive
</option>
<option value="A2 Negative">
A2 Negative
</option>
<option value="A1B Possitive">
A1B Possitive
</option>
<option value="A2B\+">
A2B+
</option>
<option value="A2B Negative">
A2B Negative
</option>
<option value="AB Possitive">
AB Possitive
</option>
<option value="AB Negative">
AB Negative
</option>
<option value="B Possitive">
B Possitive
</option>
<option value="B Negative">
B Negative
</option>
<option value="O Possitive">
O Possitive
</option>
<option value="O Negative">
O Negative
</option>
</select>
</div>
</div>
<!-- Textarea -->
<div class="form-group">
<label class="col-md-4 control-label" for="address">
Address
</label>
<div class="col-md-4">
<textarea class="form-control" id="address" required="" value="<?php echo $rlk['address'];?>" name="address">
default Address
</textarea>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="loc">
Location
</label>
<div class="col-md-4">
<input id="loc" name="loc" type="text" required="" value="<?php echo $rlk['loc'];?>" class="form-control input-md" required="">
<span class="help-block">
currently living in
</span>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="mobile">
Mobile
</label>
<div class="col-md-4">
<input id="phone" name="phone" type="number" value="<?php echo $rlk['phone'];?>" class="form-control input-md" required="">
<span class="help-block">
Mobile Number
</span>
</div>
</div>
<button type="submit" class="btn btn-primary" name="btn-save" id="btn-save">
<span class="glyphicon glyphicon-plus">
</span> Save this Record
</button>
</fieldset>
</form>
</body>
</html>
请请更正错误 在此先感谢
这是编辑Action.php文件,它是保存/更新数据库:
<?php
$status = "";
require('dbcon.php');
if(isset($_GET['new']) && $_GET['new']==1)
{
/*Detecting Input Start */
$s_id =$_GET['chk'];
$f_name = $_GET['f_name'];
$l_name = $_GET['l_name'];
$dob = $_GET['dob'];
$rln = $_GET['roll_no'];
$cls = $_GET['cls'];
$gender = $_GET['gender'];
$address= $_GET['address'];
$reli = $_GET['reli'];
$commu = $_GET['commu'];
$loc = $_GET['loc'];
$phone = $_GET['phone'];
$blg = $_GET['blg'];
/*Detection Input End */
$update=UPDATE `school`.`stu_info` SET `Roll_no` = "$rln", `f_name` = "$f_name", `l_name` = "$l_name", `dob` = "$dob", `std` = "$cls", `gender` = "$gender", `address` = "$address", `loc` = "$loc", `phone` = "$phone", `blg` = "$blg", `commu` = "$commu" WHERE `stu_info`.`s_id` = "$s_id";
$df=mysqli_query($conl,$update);
if(!df){
echo "error";
}
else {
echo "success";
}
}
?>
请通过Findout错误帮助我 在此先感谢
///我更新了我最近的代码 仍然无效显示错误
答案 0 :(得分:0)
第25行应
$update = "UPDATE `school` . `stu_info` SET `Roll_no` = '$rln', `f_name` = '$f_name', `l_name` = '$l_name', `dob` = '$dob', `std` = '$cls', `gender` = '$gender', `address` = '$address', `loc` = '$loc', `phone` = '$phone', `blg` = '$blg', `commu` = '$commu' WHERE `stu_info` . `s_id` = '$s_id''";
你最后错过了一个}。
但请不要创建这样的查询。
此问题在此处解释mysql extension deprecated
答案 1 :(得分:0)
您的代码非常不安全。 E. g。不建议直接从$ _GET数组读取。请考虑使用PDO并执行increase security
else {
$update= 'UPDATE `school`.`stu_info` SET `Roll_no` = "$rln", `f_name` = "$f_name", `l_name` = "$l_name", `dob` = "$dob", `std` = "$cls", `gender` = "$gender", `address` = "$address", `loc` = "$loc", `phone` = "$phone", `blg` = "$blg", `commu` = "$commu" WHERE `stu_info`.`s_id` = "$s_id"';
$df=mysqli_query($conl,$update);
} // missing !