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>