php post无法使用get值
我只是想给用户一个编辑选项,而页面是通过他的id获得的,但当用提交按钮更新时,它似乎不起作用。这是我的密码php post无法使用get值,php,html,Php,Html,我只是想给用户一个编辑选项,而页面是通过他的id获得的,但当用提交按钮更新时,它似乎不起作用。这是我的密码 <?php session_start(); include 'db.php'; if(isset($_GET['id'])){ $stid = $_GET['id']; $query = mysqli_query($con, "SELECT * FROM socio WHERE id = '$stid'") or die (mysqli_error())
<?php
session_start();
include 'db.php';
if(isset($_GET['id'])){
$stid = $_GET['id'];
$query = mysqli_query($con, "SELECT * FROM socio WHERE id = '$stid'") or die (mysqli_error());
$result = mysqli_num_rows($query);
if($result == 0 || $result == NULL){
echo '<div class="alert alert-danger alert-dismissible fade in"><a class="close" data-dismiss="alert" aria-label="close">×</a><strong><center>Sorry, Error while updating data!</center></strong></div>';
}else {
while($row = mysqli_fetch_array($query)){
$id = $row['id'];
$name = $row['name'];
$fname = $row['fname'];
$age = $row['age'];
$dob = $row['dob'];
$gender = $row['gender'];
$year = $row['year'];
$stGr = $row['stgroup'];
$add = $row['stadd'];
$photo = $row['photo'];
?>
请按如下方式更改链接(将“/”更改为“&”)
首先,在隐藏的输入字段中发送您的id,如下所示:
<form enctype="multipart/form-data" method="POST">
<input type="hidden" name="id" class="form-control" value="<?php echo $id; ?>">
<label>Name of the Student</label>
<input type="text" name="stName" class="form-control" value="<?php echo $name; ?>">
<label>Father/Mother/Guardian of the Student</label>
<input type="text" name="stFnam" class="form-control" value="<?php echo $fname; ?>">
<label>Date of Birth the Student</label>
<input type="text" name="stDob" value="<?php echo $dob; ?>" class="form-control">
<label>Age of the Student</label>
<input type="text" name="stAge" value="<?php echo $age; ?>" class="form-control">
<label>Gender of the Student   </label>
<input type="radio" name="stGen" id="inlineRadio1" value="Male" <?php echo ($gender == 'Male')? 'checked':''; ?>/>  Male 
<input type="radio" name="stGen" id="inlineRadio2" value="Female" <?php echo ($gender == 'Female')? 'checked':''; ?>/>  Female 
<label>Academic Year</label>
<select name="stYear" class="form-control">
<option value="2014-15" <?php echo ($year == '2014-15')? 'selected':''; ?>>2014-15</option>
<option value="2015-16" <?php echo ($year == '2015-16')? 'selected':''; ?>>2015-16</option>
<option value="2016-17" <?php echo ($year == '2016-17')? 'selected':''; ?>>2016-17</option></select>
<label>Academic Group</label>
<select name="stGroup" class="form-control">
<option value="Pre-Primary" <?php echo ($stGr == 'Pre-Primary')? 'selected':''; ?>>Pre-Primary</option>
<option value="Primary" <?php echo ($stGr == 'Primary')? 'selected':''; ?>>Primary</option>
<option value="Secondary" <?php echo ($stGr == 'Secondary')? 'selected':''; ?>>Secondary</option>
<option value="Pre-Vocational" <?php echo ($stGr == 'Pre-Vocational')? 'selected':''; ?>>Pre-Vocational</option>
<option value="Vocational" <?php echo ($stGr == 'Vocational')? 'selected':''; ?>>Vocational</option>
</select>
<label>Address of the Student</label>
<textarea name="stAdd" class="form-control" rows="6" ><?php echo $add; ?></textarea>
<label>Photo of the Student     
<label class="btn btn-default btn-file"><input type="file" name="photo">
</label><?php echo $photo; ?></label>
<button type="submit" name="submit" class="btn btn-success" >Submit</button></form>
将id
作为hidden
字段传递并使用$\u POST
访问它,你能给我一个例子吗?有两个链接,将两个链接中的字符“/”改为“&”,即将“Profile Edit.php?id=”.$id./name=”.$name.“”改为“Profile Edit.php?id=”.$id.&name=”.$name.$name.“,其与我的链接相同区别是“/”应该改为“&”,其他都可以了你现在拿到身份证了吗?请检查,如果id即将到来,请检查插入查询并将其更改为,$sql=mysqli_查询($con,“更新社会集名称='$stnam',fname='$stfnam',年龄='$stage',dob='$stdob',性别='$stgen',年份='$styer',stgroup='$stGr stadd'$stadd照片='$pic其中id='$stid');上面说数据上传了,但没有改变,我的意思是认真检查你的查询,直接在SQL中运行,检查查询是否正常。
<form enctype="multipart/form-data" method="POST">
<label>Name of the Student</label>
<input type="text" name="stName" class="form-control" value="<?php echo $name; ?>">
<label>Father/Mother/Guardian of the Student</label>
<input type="text" name="stFnam" class="form-control" value="<?php echo $fname; ?>">
<label>Date of Birth the Student</label>
<input type="text" name="stDob" value="<?php echo $dob; ?>" class="form-control">
<label>Age of the Student</label>
<input type="text" name="stAge" value="<?php echo $age; ?>" class="form-control">
<label>Gender of the Student   </label>
<input type="radio" name="stGen" id="inlineRadio1" value="Male" <?php echo ($gender == 'Male')? 'checked':''; ?>/>  Male 
<input type="radio" name="stGen" id="inlineRadio2" value="Female" <?php echo ($gender == 'Female')? 'checked':''; ?>/>  Female 
<label>Academic Year</label>
<select name="stYear" class="form-control">
<option value="2014-15" <?php echo ($year == '2014-15')? 'selected':''; ?>>2014-15</option>
<option value="2015-16" <?php echo ($year == '2015-16')? 'selected':''; ?>>2015-16</option>
<option value="2016-17" <?php echo ($year == '2016-17')? 'selected':''; ?>>2016-17</option>
</select>
<label>Academic Group</label>
<select name="stGroup" class="form-control">
<option value="Pre-Primary" <?php echo ($stGr == 'Pre-Primary')? 'selected':''; ?>>Pre-Primary</option>
<option value="Primary" <?php echo ($stGr == 'Primary')? 'selected':''; ?>>Primary</option>
<option value="Secondary" <?php echo ($stGr == 'Secondary')? 'selected':''; ?>>Secondary</option>
<option value="Pre-Vocational" <?php echo ($stGr == 'Pre-Vocational')? 'selected':''; ?>>Pre-Vocational</option>
<option value="Vocational" <?php echo ($stGr == 'Vocational')? 'selected':''; ?>>Vocational</option>
</select>
<label>Address of the Student</label>
<textarea name="stAdd" class="form-control" rows="6"><?php echo $add; ?></textarea>
<label>
Photo of the Student     
<label class="btn btn-default btn-file">
<input type="file" name="photo">
</label><?php echo $photo; ?>
</label>
<button type="submit" name="submit" class="btn btn-success">Submit</button>
</form>
<?php
include 'db.php';
if(isset($_POST['submit'])){
$stid = $_GET['id'];
$target = "images/";
$target = $target . basename( $_FILES['photo']['name']);
$stnam = $_POST['stName'];
$stfnam = $_POST['stFnam'];
$stage = $_POST['stAge'];
$stdob = $_POST['stDob'];
$stgen = $_POST['stGen'];
$styer = $_POST['stYear'];
$stGr = $_POST['stGroup'];
$stadd = $_POST['stAdd'];
$pic = $_FILES['photo']['name'];
$allowed = array('gif','png' ,'jpg', 'pdf');
$ext = pathinfo($pic, PATHINFO_EXTENSION);
if(!in_array($ext,$allowed)) {
$picmess = "Upload PDF/png/jpeg format only";
echo "<script type='text/javascript'>alert('$picmess');</script>";
}else{
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{
$sql = mysqli_query($con, "UPDATE socio SET (name = '$stnam', fname = '$stfnam', age = '$stage', dob = '$stdob', gender = '$stgen', year = '$styer', stgroup = '$stGr', stadd = '$stadd', photo = '$pic' WHERE id = '$stid')");
$sucmess = "Data Uploaded Successfully";
echo '<div class="alert alert-info alert-dismissible fade in"><a class="close" data-dismiss="alert" aria-label="close">×</a><strong><center>'.$sucmess.'</center></strong></div>';
}
else{
$errmess = "Data Not Uploaded Successfully";
echo '<div class="alert alert-info alert-dismissible fade in"><a class="close" data-dismiss="alert" aria-label="close">×</a><strong><center>'.$errmess.'</center></strong></div>';
}
}
mysqli_close($con);
}
?>
<?php echo '<center><a href="Profile-Edit.php?id='.$id.'&name='.$name.'" class="btn btn-primary" role="button">Edit/Update</a> <a href="Profile-Edit.php?id='.$id.'&name='.$name.'" class="btn btn-primary" role="button">Delete</a></center>';?>
$sql = mysqli_query($con, "UPDATE socio SET name = '$stnam', fname = '$stfnam', age = '$stage', dob = '$stdob', gender = '$stgen', year = '$styer', stgroup = '$stGr', stadd = '$stadd', photo = '$pic' WHERE id = '$stid'");
<form enctype="multipart/form-data" method="POST">
<input type="hidden" name="id" class="form-control" value="<?php echo $id; ?>">
<label>Name of the Student</label>
<input type="text" name="stName" class="form-control" value="<?php echo $name; ?>">
<label>Father/Mother/Guardian of the Student</label>
<input type="text" name="stFnam" class="form-control" value="<?php echo $fname; ?>">
<label>Date of Birth the Student</label>
<input type="text" name="stDob" value="<?php echo $dob; ?>" class="form-control">
<label>Age of the Student</label>
<input type="text" name="stAge" value="<?php echo $age; ?>" class="form-control">
<label>Gender of the Student   </label>
<input type="radio" name="stGen" id="inlineRadio1" value="Male" <?php echo ($gender == 'Male')? 'checked':''; ?>/>  Male 
<input type="radio" name="stGen" id="inlineRadio2" value="Female" <?php echo ($gender == 'Female')? 'checked':''; ?>/>  Female 
<label>Academic Year</label>
<select name="stYear" class="form-control">
<option value="2014-15" <?php echo ($year == '2014-15')? 'selected':''; ?>>2014-15</option>
<option value="2015-16" <?php echo ($year == '2015-16')? 'selected':''; ?>>2015-16</option>
<option value="2016-17" <?php echo ($year == '2016-17')? 'selected':''; ?>>2016-17</option></select>
<label>Academic Group</label>
<select name="stGroup" class="form-control">
<option value="Pre-Primary" <?php echo ($stGr == 'Pre-Primary')? 'selected':''; ?>>Pre-Primary</option>
<option value="Primary" <?php echo ($stGr == 'Primary')? 'selected':''; ?>>Primary</option>
<option value="Secondary" <?php echo ($stGr == 'Secondary')? 'selected':''; ?>>Secondary</option>
<option value="Pre-Vocational" <?php echo ($stGr == 'Pre-Vocational')? 'selected':''; ?>>Pre-Vocational</option>
<option value="Vocational" <?php echo ($stGr == 'Vocational')? 'selected':''; ?>>Vocational</option>
</select>
<label>Address of the Student</label>
<textarea name="stAdd" class="form-control" rows="6" ><?php echo $add; ?></textarea>
<label>Photo of the Student     
<label class="btn btn-default btn-file"><input type="file" name="photo">
</label><?php echo $photo; ?></label>
<button type="submit" name="submit" class="btn btn-success" >Submit</button></form>
include 'db.php';
if(isset($_POST['submit'])){
$stid = $_POST['id'];
$target = "images/";
$target = $target . basename( $_FILES['photo']['name']);
$stnam = $_POST['stName'];
$stfnam = $_POST['stFnam'];
$stage = $_POST['stAge'];
$stdob = $_POST['stDob'];
$stgen = $_POST['stGen'];
$styer = $_POST['stYear'];
$stGr = $_POST['stGroup'];
$stadd = $_POST['stAdd'];
$pic = $_FILES['photo']['name'];
$allowed = array('gif','png' ,'jpg', 'pdf');
$ext = pathinfo($pic, PATHINFO_EXTENSION);
if(!in_array($ext,$allowed)) {
$picmess = "Upload PDF/png/jpeg format only";
echo "<script type='text/javascript'>alert('$picmess');</script>";
}else{
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{
$sql = mysqli_query($con, "UPDATE socio SET (name = '$stnam', fname = '$stfnam', age = '$stage', dob = '$stdob', gender = '$stgen', year = '$styer', stgroup = '$stGr', stadd = '$stadd', photo = '$pic' WHERE id = '$stid')");
$sucmess = "Data Uploaded Successfully";
echo '<div class="alert alert-info alert-dismissible fade in"><a class="close" data-dismiss="alert" aria-label="close">×</a><strong><center>'.$sucmess.'</center></strong></div>';
}
else{
$errmess = "Data Not Uploaded Successfully";
echo '<div class="alert alert-info alert-dismissible fade in"><a class="close" data-dismiss="alert" aria-label="close">×</a><strong><center>'.$errmess.'</center></strong></div>';
}
}
mysqli_close($con);
}
?>