php - 显示更新成功警报但无法单击警报,并且数据库未更新

标签 php jquery mysql ajax

当我点击更新时,页面只会刷新,值不会更新。我在数据库中有 4 个表,即 -> stud、country_master_academic、master_state、master_city。在控制台中,单击更新按钮时未显示值。

我的 update.php 页面

 <div class="container" style="width:700px;height:1100px;margin-top:10%;box-shadow:4px 3px 3px 3px grey;margin-left:25%;background-color:#eaf2fa;padding:3%;">

                <h4 style="font-weight:bold;"><span class="glyphicon glyphicon-edit"></span>Update Student</h4>


                <div class="form-group">

                    <label for="photo"></label>
                    <?php
                $img = "images/".trim($vrow["photo"]);
                echo '<img src='.$img.' id="resultedPhoto" class="image" style="margin-left:75%;margin-top:2%;width:120px;height:120px;border:2px solid #bbbbbb;border-radius:10px;">';
                ?><br/>
                    <input type="file" name="upphoto" id="upphoto" style="margin-left:70%;" required />
                </div>

                <form class="form-horizontal" name="form1" id="form1" method="post" action="<?php $_PHP_SELF?>" enctype="multipart/form-data">
                    <div class="form-group">
                    <label for="no"><span class="glyphicon glyphicon-lock"></span><b> Student No: </b></label>
                    <input type="text" class="form-control" name="upno" id="upno" disabled value="<?php echo $vrow['stud_no'];?>" required />
                </div>
                    <div class="form-group">
                    <label for="name"><span class="glyphicon glyphicon-user"></span><b> Student Name: </b></label>
                    <input type="text" class="form-control" name="upname" id="upname" value="<?php echo $vrow['stud_name'];?>" required pattern="[a-zA-Z]{3,}" title="Name should only contain letters and atleast 3 letters"/>
                </div>
                <div class="form-group">
                    <label for="no"><span class="glyphicon glyphicon-phone"></span><b> Mobile No: </b></label>
                    <input type="text" class="form-control" value="<?php echo $vrow['mobile']; ?>" name="upmob_no" required id="upmob_no" pattern="[0-9]{10}" title="Mobile number should be of 10 digits"/>
                </div>
                <div class="form-group">    
                    <label for="dob"><span class="glyphicon glyphicon-calendar"></span><b> Birth Date: </b></label>
                    <input type="date" required class="form-control" value="<?php echo $vrow['dob'];?>"  name="updob" id="updob" />
                </div>
                <div class="form-group">
                    <label for="add"><span class="glyphicon glyphicon-map-marker"></span><b> Address: </b></label>
                    <textarea rows="4" cols="33" class="form-control" name="upadd" id="upadd" required><?php echo $vrow['address'];?></textarea>
                </div>

                <div class="form-group">
                    <label for="gen"><b> Gender: </b></label>
                    <input type="radio" name="gender" id="genderMale" value="M"<?php echo ($vrow['gender']=='M')?'checked':' ' ?> required="required">Male
                    <input type="radio" name="gender" id="genderFemale"  value="F"<?php echo ($vrow['gender']=='F')?'checked':' ' ?> required="required">Female
                </div>
                <div class="form-group">
                    <label for="cntry"><span class="glyphicon glyphicon-map-marker"></span><b> Country: </b></label>
                <select required name="upcountry" id="upcountry" class="form-control">
                <option value="">Select</option>
                    <?php 
                    $country="SELECT * from country_master_academic";
                    $res= $conn->query($country);
                    if($res->num_rows>0){
                        while($row=$res->fetch_assoc()){        
                        if($row["country_name"]==$vcountry or $vrow['country'] == $row["country_code"] )
                        {   
                                echo '<option value='.$row["country_code"].' selected>'.$row["country_name"].'</option>';
                        }
                            else
                            {
                                echo '<option value='.$row["country_code"].'>'.$row["country_name"].'</option>';
                            }
                        }
                    }
                ?>
                </select>

                </div>
                <div class="form-group">
                        <label for="state"><span class="glyphicon glyphicon-map-marker"></span><b> State: </b></label>
                <select required name="upstate" id="upstate" class="form-control">
                <option value="">Select</option>
                    <?php 
                    $state="SELECT * from master_state";
                    $res= $conn->query($state);
                    if($res->num_rows>0){
                        while($row=$res->fetch_assoc()){        
                        if($row["state_name"]==$vstate or $vrow['state'] == $row["state_code"] )
                        {   
                                echo '<option value='.$row["state_code"].' selected>'.$row["state_name"].'</option>';
                        }
                            else
                            {
                                echo '<option value='.$row["state_code"].'>'.$row["state_name"].'</option>';
                            }
                        }
                    }
                ?>
                </select>
                    </div>
                <div class="form-group">
                <label for="city"><span class="glyphicon glyphicon-map-marker"></span><b> City: </b></label>
                <select required name="upcity" id="upcity" class="form-control">
                <option value="">Select</option>
                    <?php 
                    $city="SELECT * from master_city";
                    $res= $conn->query($city);
                    if($res->num_rows>0){
                        while($row=$res->fetch_assoc()){        
                        if($row["city_name"]==$vcity or $vrow['city'] == $row["city_code"] )
                        {   
                                echo '<option value='.$row["city_code"].' selected>'.$row["city_name"].'</option>';
                        }
                            else
                            {
                                echo '<option value='.$row["city_code"].'>'.$row["city_name"].'</option>';
                            }
                        }
                    }
                ?>
                </select>
                </div>
                <br/>
                <div class="form-group">
                    <button type="submit" name="update" id="update" style="font-weight:bold;" class="btn btn-primary">Update</button>
                </div>
                </form>

</div> 

upresult.php页面

    <?php
    include("connection.php");

$no=trim($_POST['upno']);
$name=trim($_POST['upname']);
$mob=trim($_POST['upmob_no']);
$dob=trim($_POST['updob']);
$add=trim($_POST['upadd']);
$photo=trim($_FILES['upphoto']['name']);
$gen=trim($_POST['gender']);
$cn=trim($_POST['upcountry']);
$st=trim($_POST['upstate']);
$ct=trim($_POST['upcity']);

$qry="update stud set stud_name='".$name."',mobile='".$mob."',dob='".$dob."',address='".$add."',gender='".$gen."',country='".$cn."',state='".$st."',city='".$ct."' where stud_no='".$no."'";
$data=mysqli_query($conn,$qry);
if($data)
{
        echo '<script language="javascript">';
        echo 'alert("Updated Successfully")';
        echo '</script>';
    }
    else {
        echo '<script language="javascript">';
        echo 'alert("Cannot update record")';
        echo '</script>';
    }

?>

j查询

 $(document).ready(function(){

        $("#form1").submit(function(event){
            event.preventDefault();
            var formData = new FormData(this);
              $.ajax({

                 url:"upresult.php",
                 type:"POST",
                 data:{formData:formData},
                 async:true,
                 success:function(data) {
                   alert(data);
                },
                cache:false,
                contentType:false,
                processData:false
            });
         });
    });

提前谢谢你。

最佳答案

不要使用相同的名字

 data:{stud_no:stud_no},  //here change the name of vbl or  value
data:{
formData:formData, //here change the name of vbl or  value
stud_no:stud_no, //here change the name of vbl or  value
}

关于php - 显示更新成功警报但无法单击警报,并且数据库未更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53551852/

相关文章:

php - MySQL 查询 : find the category id in the products table, 但是 id 被包装成 `&12&`

php - 拉维尔 5.4 : Directly Subtract number from column in database

php - 从登录中提取数据?

javascript - 使用ajax将多维数组数据发送到php脚本

jquery - 将对象列表发布到 MVC 5 Controller

javascript - mouseover 和 mouseenter 事件有什么区别?

javascript - 单击图像到 div 时如何显示文本

mysql - 从1开始截断后插入;但删除后插入会从之前的值恢复

c# - 插入图片到Mysql出错

c++ - 在 MySQL 中运行 HTTP 服务器以接收来自客户端的数据