dongpu2694 2014-11-21 05:34
浏览 47
已采纳

更新查询更新不起作用

I am doing Add, Update and Delete in Php.

Everything is working fine but My Update query is not working.

Can I know, where i am going wrong in Update query?

Here is my update.php file code..

<?php

include('connection.php'); 

$ID = $_REQUEST['Student_Id'];

$result = mysql_query("select* from tblstudent where Student_Id='".$ID."'");

while($oldvalue=  mysql_fetch_array($result))

{
    $oldname=$oldvalue['Student_Name'];
    $oldgender=$oldvalue['Gender'];
    $olddob=$oldvalue['DOB'];
    $oldaddress=$oldvalue['Address'];
    $oldmobileno=$oldvalue['Phone'];
    $olddivision=$oldvalue['Division'];
    $oldclass=$oldvalue['Class'];
    $oldemail=$oldvalue['Email_Id'];

}

if(isset ($_POST['submit']))
{

    $update = $_POST['submit'];

        if($update)
        {
            $newname=$_POST['Student_Name'];
            $newgender=$_POST['Gender'];
            $newdob=$_POST['DOB'];
            $newaddress=$_POST['Address'];
            $newmobileno=$_POST['Phone'];
            $newdivision=$_POST['Division'];
            $newclass=$_POST['Class'];
            $newemail=$_POST['Email_Id'];
    
          /* UPDATE QUERY */                        

           mysql_query("UPDATE tblstuent SET Student_Name='$newname', Gender='$newgender', DOB='$newdob', Address='$newaddress', Phone='$newmobileno', Division='$newdivision', Class='$newclass', Email_Id='$newemail'
                   WHERE id='$ID'");
            
            header('location:index.php');
        }
}

?>

<body>
         <form action="update.php" method="post">
                
                <fieldset>
                
                    <legend>Personal Information</legend><br/>   
                    
                    <div class="studentname"><label>Student Name :</label><input type="text" name="newstudentname" id="studentnameId" value="<?php echo $oldname ?>" placeholder="Enter Name" size="30px" /></div><br/>
                    
                    <div class="gender">
           
                         <label>Gender :</label>
                         
                         <input type="radio" name="type" value="Male" <?php echo ($oldgender == 'Male') ? 'checked' : ''; ?> />  Male
                         <input type="radio" name="type" value="Female" <?php echo ($oldgender == 'Female') ? 'checked' : ''; ?>/> Female<br />

                    </div> <br/>
                    
                    <div class="dob"><label>Date of Birth :</label><input type="text" name="dob" id="dobId" value="<?php echo $olddob ?>" placeholder="Enter DOB format Year-Month-DaY" size="30px" /></div><br/>
                    
                    <div class="address"><label class="addresschild">Address : </label><textarea rows="4" cols="21" name="address" id="addressId" value="" placeholder="Enter Your Address"><?php echo $oldaddress ?></textarea></div><br/>

                    <div class="mobileno"><label>Parent's Mobile No : </label><input type="text" name="mobileno" id="mobilenoId" value="<?php echo $oldmobileno ?>" placeholder="Enter Parent's Mobile No" size="30px" /></div><br/>
                    
                    <div class="selectdivision">
                        
                        <label>Divison :</label>

                        <select id="divisiondropdownId" name="divisiondropdown">
                            <option value="0">Select Division</option>
                            <option value="A"<?php if($olddivision=="A") echo 'selected="selected"'; ?> >A</option>
                            <option value="B"<?php if($olddivision=="B") echo 'selected="selected"'; ?> >B</option>
                            <option value="C"<?php if($olddivision=="C") echo 'selected="selected"'; ?> >C</option>
                        </select>
                        
                    </div><br/>
                    
                    <div class="selectclass">
                        
                        <label>Class :</label>
                        
                        <select id="classdropdownId" name="classdropdown">
                        
                            <option value="0">Select Class</option>
                            <option value="First"<?php if($oldclass=="First") echo 'selected="selected"'; ?>>First</option>
                            <option value="Second"<?php if($oldclass=="Second") echo 'selected="selected"'; ?>>Second</option>
                            <option value="Third"<?php if($oldclass=="Third") echo 'selected="selected"'; ?>>Third</option>
                            <option value="Fourth"<?php if($oldclass=="Fourth") echo 'selected="selected"'; ?>>Fourth</option>
                            <option value="Fifth"<?php if($oldclass=="Fifth") echo 'selected="selected"'; ?>>Fifth</option>
                            <option value="Sixth"<?php if($oldclass=="Sixth") echo 'selected="selected"'; ?>>Sixth</option>
                            <option value="Seventh"<?php if($oldclass=="Seventh") echo 'selected="selected"'; ?>>Seventh</option>
                            <option value="Eighth"<?php if($oldclass=="Eighth") echo 'selected="selected"'; ?>>Eighth</option>
                            <option value="Nineth"<?php if($oldclass=="Nineth") echo 'selected="selected"'; ?>>Nineth</option>
                            <option value="Tenth"<?php if($oldclass=="Tenth") echo 'selected="selected"'; ?>>Tenth</option>
                        
                        </select>
                        
                    </div><br/>
                    
                    
                    <div class="emailid"><label>Email-Id : </label><input type="text" name="emailid" id="emailId" value="<?php echo $oldemail ?>" placeholder="Enter your Email-id" size="30px" /></div><br/>
                   
                    
                    <div id="submit1">
                        
                        <input class="btnsubmit" type="submit" name="submit" id="submit" value="Submit" />
                        
                        <input class="btnreset" type="reset" name="reset" id="submit" value="Reset" />
                    
                    </div><br/>

                </fieldset>

            </form>
</body>

Thank you

Rahul Barge

</div>
  • 写回答

8条回答 默认 最新

  • drygauost253590142 2014-12-01 07:48
    关注

    Hello Friends thank you,

    All your answers helped me to solve problem.

    I learn alot from you all.

    Finally i solved above problem doing some changes in update.php file code..

    Here is my new code

    <?php
    
    include('connection.php'); 
    
    if(isset ($_REQUEST['Student_Id']))
    {
        $id = $_REQUEST['Student_Id'];
        
        $result = mysql_query("select* from tblstudent where Student_Id ='".$id."'");
        
        while($oldvalue=  mysql_fetch_array($result))
        {
    
        $oldid = $oldvalue['Student_Id'];
        $oldname=$oldvalue['Student_Name'];
        $oldgender=$oldvalue['Gender'];
        $olddob=$oldvalue['DOB'];
        $oldaddress=$oldvalue['Address'];
        $oldmobileno=$oldvalue['Phone'];
        $olddivision=$oldvalue['Division'];
        $oldclass=$oldvalue['Class'];
        $oldemail=$oldvalue['Email_Id'];
    
        }   
    }
    
    if(isset ($_POST['newname']))
    {
    
                $newname =$_POST['newname'];
                
                $newid =$_POST['newid'];
                
                $newgender =$_POST['newgender'];
                
                $newdob = $_POST['newdob'];
                
                $newaddress = $_POST['newaddress'];
                
                $newphone = $_POST['newphone'];
                
                $newdivision = $_POST['newdivision'];
                
                $newclass = $_POST['newclass'];
                
                $newemailid = $_POST['newemailid'];
                
                $sql= "UPDATE tblstudent SET Student_Name='$newname', Gender='$newgender', DOB='$newdob', Address='$newaddress', Phone='$newphone', Division='$newdivision', Class='$newclass', Email_Id='$newemailid' WHERE Student_Id='$newid'";
                
                $result= mysql_query($sql);
                
                header('location:index.php');
    
    }
    
    ?>
    
    
    
    <body>
             <form action="update.php" method="post">
                    
                    <fieldset>
                    
                        <legend>Personal Information</legend><br/>
                        
                        <div class="studentname"><label>Student Name :</label><input type="text" name="newname" id="studentnameId" value="<?php echo $oldname ?>" placeholder="Enter First & Last Name" size="30px" /></div><br/>
                        
                        <input type="hidden" name="newid" value="<?php echo $oldid ?>"/>
                        
                        <div class="gender">
               
                             <label>Gender :</label>
                             
                             <input type="radio" name="newgender" value="Male" <?php echo ($oldgender == 'Male') ? 'checked' : ''; ?> />  Male
                             <input type="radio" name="newgender" value="Female" <?php echo ($oldgender == 'Female') ? 'checked' : ''; ?>/> Female<br />
    
    
                        </div> <br/>
                        
                        <div class="dob"><label>Date of Birth :</label><input type="text" name="newdob" id="dobId" value="<?php echo $olddob ?>" placeholder="Enter DOB format Year-Month-DaY" size="30px" /></div><br/>
                        
                        <div class="address"><label class="addresschild">Address : </label><textarea rows="4" cols="21" name="newaddress" id="addressId" value="" placeholder="Enter Your Address"><?php echo $oldaddress ?></textarea></div><br/>
    
                        <div class="mobileno"><label>Parent's Mobile No : </label><input type="text" name="newphone" id="mobilenoId" value="<?php echo $oldmobileno ?>" placeholder="Enter Parent's Mobile No" size="30px" /></div><br/>
                        
                        <div class="selectdivision">
                            
                            <label>Divison :</label>
    
                            <select id="divisiondropdownId" name="newdivision">
                                <option value="0">Select Division</option>
                                <option value="A"<?php if($olddivision=="A") echo 'selected="selected"'; ?> >A</option>
                                <option value="B"<?php if($olddivision=="B") echo 'selected="selected"'; ?> >B</option>
                                <option value="C"<?php if($olddivision=="C") echo 'selected="selected"'; ?> >C</option>
                            </select>
                            
                            
                            
                        </div><br/>
                        
                        <div class="selectclass">
                            
                            <label>Class :</label>
                            
                            <select id="classdropdownId" name="newclass">
                            
                                <option value="0">Select Class</option>
                                <option value="First"<?php if($oldclass=="First") echo 'selected="selected"'; ?>>First</option>
                                <option value="Second"<?php if($oldclass=="Second") echo 'selected="selected"'; ?>>Second</option>
                                <option value="Third"<?php if($oldclass=="Third") echo 'selected="selected"'; ?>>Third</option>
                                <option value="Fourth"<?php if($oldclass=="Fourth") echo 'selected="selected"'; ?>>Fourth</option>
                                <option value="Fifth"<?php if($oldclass=="Fifth") echo 'selected="selected"'; ?>>Fifth</option>
                                <option value="Sixth"<?php if($oldclass=="Sixth") echo 'selected="selected"'; ?>>Sixth</option>
                                <option value="Seventh"<?php if($oldclass=="Seventh") echo 'selected="selected"'; ?>>Seventh</option>
                                <option value="Eighth"<?php if($oldclass=="Eighth") echo 'selected="selected"'; ?>>Eighth</option>
                                <option value="Nineth"<?php if($oldclass=="Nineth") echo 'selected="selected"'; ?>>Nineth</option>
                                <option value="Tenth"<?php if($oldclass=="Tenth") echo 'selected="selected"'; ?>>Tenth</option>
                            
                            </select>
                            
                        </div><br/>
                        
                        
                        <div class="emailid"><label>Email-Id : </label><input type="text" name="newemailid" id="emailId" value="<?php echo $oldemail ?>" placeholder="Enter your Email-id" size="30px" /></div><br/>
                       
                        
                        <div id="submit1">
                            
                            <input class="btnsubmit" type="submit" name="submit" id="submit" value="Submit" />
                            
                            <input class="btnreset" type="reset" name="reset" id="submit" value="Reset" />
                        
                        </div><br/>
    
                    </fieldset>
    
                </form>
    </body>

    Thank you :-)

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(7条)

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集