0

i have created a database.i have values inserted from the html form.now i need to view the data on giving childid. i should able to edit it and update into the database. i have created 3 php .can anyone help

1.phpMySQLEditRecordList.php

<html>
<head>
<title>edit record list</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","school","certify") or die("Error Connect to Database");
$objDB = mysql_select_db("school");
$strSQL = "SELECT * FROM childinfo";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>

<table width="600" border="1">
<tr>
<th width="91"> <div align="center">ChildID </div></th>
<th width="98"> <div align="center">ParentID </div></th>
<th width="198"> <div align="center">SiblingsID </div></th>
<th width="97"> <div align="center">TeacherID </div></th>
<th width="59"> <div align="center">ChildName </div></th>
<th width="71"> <div align="center">DOB </div></th>
<th width="30"> <div align="center">Age </div></th>
<th width="91"> <div align="center">Gender </div></th>
<th width="98"> <div align="center">Grade </div></th>
<th width="198"> <div align="center">Section </div></th>
<th width="97"> <div align="center">Stream </div></th>
<th width="59"> <div align="center">BloodGroup </div></th>
<th width="71"> <div align="center">Nationality </div></th>
<th width="30"> <div align="center">Country </div></th>
<th width="91"> <div align="center">Religion </div></th>
<th width="98"> <div align="center">MotherTongue </div></th>
<th width="198"> <div align="center">FirstLanguage </div></th>
<th width="97"> <div align="center">SecondLanguage </div></th>
<th width="59"> <div align="center">PlaceOfBirth </div></th>
<th width="71"> <div align="center">LandlineNumber </div></th>
<th width="30"> <div align="center">EmailID </div></th>
<th width="91"> <div align="center">ChildPhoto </div></th>
<th width="98"> <div align="center">TemporaryAddress </div></th>
<th width="198"> <div align="center">PermanentAddress </div></th>
<th width="97"> <div align="center">Mentor </div></th>
<th width="59"> <div align="center">DateOfJoin </div></th>
<th width="71"> <div align="center">JoinGrade </div></th>
<th width="97"> <div align="center">ReferredBy </div></th>
<th width="59"> <div align="center">ContactNumber </div></th>
<th width="71"> <div align="center">EmergencyContactNumber </div></th>
<th width="30"> <div align="center">Edit </div></th>
</tr>

<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td><div align="center"><?=$objResult["ChildID"];?></div></td>
<td><?=$objResult["ParentID"];?></td>
<td><?=$objResult["SiblingsID"];?></td>
<td><div align="center"><?=$objResult["TeacherID"];?></div></td>
<td align="right"><?=$objResult["ChildName"];?></td>
<td align="right"><?=$objResult["DOB"];?></td>
<td><?=$objResult["Age"];?></td>
<td><?=$objResult["Gender"];?></td>
<td><div align="center"><?=$objResult["Grade"];?></div></td>
<td align="right"><?=$objResult["Section"];?></td>
<td align="right"><?=$objResult["Stream"];?></td>
<td><?=$objResult["BloodGroup"];?></td>
<td><?=$objResult["Nationality"];?></td>
<td><div align="center"><?=$objResult["Country"];?></div></td>
<td align="right"><?=$objResult["Religion"];?></td>
<td align="right"><?=$objResult["MotherTongue"];?></td>
<td><?=$objResult["FirstLanguage"];?></td>
<td><?=$objResult["SecondLanguage"];?></td>
<td><div align="center"><?=$objResult["PlaceOfBirth"];?></div></td>
<td align="right"><?=$objResult["LandlineNumber"];?></td>
<td align="right"><?=$objResult["EmailID"];?></td>
<td><?=$objResult["ChildPhoto"];?></td>
<td><?=$objResult["TemporaryAddress"];?></td>
<td><div align="center"><?=$objResult["PermanentAddress"];?></div></td>
<td align="right"><?=$objResult["Mentor"];?></td>
<td align="right"><?=$objResult["DateOfJoin"];?></td>
<td><?=$objResult["JoinGrade"];?></td>
<td><?=$objResult["ReferredBy"];?></td>
<td><div align="center"><?=$objResult["ContactNumber"];?></div></td>
<td align="right"><?=$objResult["EmergencyContactNumber"];?></td>


<td align="center"><a href="phpMySQLEditRecordForm.php?ChildID=<?=$objResult["ChildID"];?>">Edit</a></td>
</tr>
<?
}
?>
</table>
<?
mysql_close($objConnect);
?>
</body>
</html>

2.phpMySQLEditRecordForm.php

<html>
<head>
<title>edit record</title>
</head>
<body>
<form action="phpMySQLEditRecordSave.php?ChildID=<?=$_GET["ChildID"];?>" name="frmEdit" method="post">
<?
$objConnect = mysql_connect("localhost","school","certify") or die("Error Connect to Database");
$objDB = mysql_select_db("school");
$strSQL = "SELECT * FROM childinfo WHERE ChildID = '".$_GET["ChildID"]."' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
if(!$objResult)
{
echo "Not found ChildID=".$_GET["ChildID"];
}
else
{
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">ChildID </div></th>
<th width="160"> <div align="center">ParentID </div></th>
<th width="198"> <div align="center">SiblingsID </div></th>
<th width="97"> <div align="center">TeacherID </div></th>
<th width="70"> <div align="center">ChildName </div></th>
<th width="70"> <div align="center">DOB </div></th>
<th width="91"> <div align="center">Age </div></th>
<th width="160"> <div align="center">Gender </div></th>
<th width="198"> <div align="center">Grade </div></th>
<th width="97"> <div align="center">Section </div></th>
<th width="70"> <div align="center">Stream </div></th>
<th width="70"> <div align="center">BloodGroup </div></th>
<th width="91"> <div align="center">Nationality </div></th>
<th width="160"> <div align="center">Country </div></th>
<th width="198"> <div align="center">Religion </div></th>
<th width="97"> <div align="center">MotherTongue </div></th>
<th width="70"> <div align="center">FirstLanguage </div></th>
<th width="70"> <div align="center">SecondLanguage </div></th>
<th width="91"> <div align="center">PlaceOfBirth </div></th>
<th width="160"> <div align="center">LandlineNumber </div></th>
<th width="198"> <div align="center">EmailID </div></th>
<th width="97"> <div align="center">ChildPhoto </div></th>
<th width="70"> <div align="center">TemporaryAddress </div></th>
<th width="70"> <div align="center">PermanentAddress </div></th>
<th width="91"> <div align="center">Mentor </div></th>
<th width="160"> <div align="center">DateOfJoin </div></th>
<th width="198"> <div align="center">JoinGrade </div></th>
<th width="97"> <div align="center">ReferredBy </div></th>
<th width="70"> <div align="center">ContactNumber </div></th>
<th width="70"> <div align="center">EmergencyContactNumber </div></th>

</tr>
<tr>
<td><div align="center"><input type="text" name="ChildID" size="5" value="<?=$objResult["ChildID"];?>"></div></td>
<td><input type="text" name="ParentID" size="20" value="<?=$objResult["ParentID"];?>"></td>
<td><input type="text" name="SiblingsID" size="20" value="<?=$objResult["SiblingsID"];?>"></td>
<td><div align="center"><input type="text" name="TeacherID" size="2" value="<?=$objResult["TeacherID"];?>"></div></td>
<td align="right"><input type="text" name="ChildName" size="5" value="<?=$objResult["ChildName"];?>"></td>
<td align="right"><input type="date" name="DOB" size="5" value="<?=$objResult["DOB"];?>"></td>
<td><div align="center"><input type="text" name="Age" size="5" value="<?=$objResult["Age"];?>"></div></td>
<td><input type="text" name="Gender" size="20" value="<?=$objResult["Gender"];?>"></td>
<td><input type="text" name="Grade" size="20" value="<?=$objResult["Grade"];?>"></td>
<td><div align="center"><input type="text" name="Section" size="2" value="<?=$objResult["Section"];?>"></div></td>
<td align="right"><input type="text" name="Stream" size="5" value="<?=$objResult["Stream"];?>"></td>
<td align="right"><input type="text" name="BloodGroup" size="5" value="<?=$objResult["BloodGroup"];?>"></td>
<td><div align="center"><input type="text" name="Nationality" size="5" value="<?=$objResult["Nationality"];?>"></div></td>
<td><input type="text" name="Country" size="20" value="<?=$objResult["Country"];?>"></td>
<td><input type="text" name="Religion" size="20" value="<?=$objResult["Religion"];?>"></td>
<td><div align="center"><input type="text" name="MotherTongue" size="2" value="<?=$objResult["MotherTongue"];?>"></div></td>
<td align="right"><input type="text" name="FirstLanguage" size="5" value="<?=$objResult["FirstLanguage"];?>"></td>
<td align="right"><input type="text" name="SecondLanguage" size="5" value="<?=$objResult["SecondLanguage"];?>"></td>
<td><input type="text" name="PlaceOfBirth" size="20" value="<?=$objResult["PlaceOfBirth"];?>"></td>
<td><div align="center"><input type="text" name="txtCountryCode" size="2" value="<?=$objResult["LandlineNumber"];?>"></div></td>
<td align="right"><input type="text" name="LandlineNumber" size="5" value="<?=$objResult["EmailID"];?>"></td>
<td align="right"><input type="text" name="ChildPhoto" size="5" value="<?=$objResult["ChildPhoto"];?>"></td>
<td><div align="center"><input type="text" name="TemporaryAddress" size="2" value="<?=$objResult["TemporaryAddress"];?>"></div></td>
<td align="right"><input type="text" name="PermanentAddress" size="5" value="<?=$objResult["PermanentAddress"];?>"></td>
<td align="right"><input type="text" name="Mentor" size="5" value="<?=$objResult["Mentor"];?>"></td>
<td><div align="center"><input type="date" name="DateOfJoin" size="2" value="<?=$objResult["DateOfJoin"];?>"></div></td>
<td align="right"><input type="text" name="JoinGrade" size="5" value="<?=$objResult["JoinGrade"];?>"></td>
<td align="right"><input type="text" name="ReferredBy" size="5" value="<?=$objResult["ReferredBy"];?>"></td>
<td align="right"><input type="tel" name="ContactNumber" size="5" value="<?=$objResult["ContactNumber"];?>"></td>
<td align="right"><input type="tel" name="EmergencyContactNumber" size="5" value="<?=$objResult["EmergencyContactNumber"];?>"></td>
</tr>
</table>
<input type="submit" name="submit" value="submit">
<?
}
mysql_close($objConnect);
?>
</form>
</body>
</html>

3.phpMySQLEditRecordSave.php

<html>
<head>
<title>edit save record</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","school","certify") or die("Error Connect to Database");
$objDB = mysql_select_db("school");
$strSQL = "UPDATE childinfo SET ";
$strSQL .="ChildID = '".$_POST["ChildID"]."' ";
$strSQL .=",ParentID = '".$_POST["ParentID"]."' ";
$strSQL .=",SiblingsID = '".$_POST["SiblingsID"]."' ";
$strSQL .=",TeacherID = '".$_POST["TeacherID"]."' ";
$strSQL .=",ChildName = '".$_POST["ChildName"]."' ";
$strSQL .="DOB = '".$_POST["DOB"]."' ";
$strSQL .=",Age = '".$_POST["Age"]."' ";
$strSQL .=",Gender = '".$_POST["Gender"]."' ";
$strSQL .=",Grade = '".$_POST["Grade"]."' ";
$strSQL .=",Section = '".$_POST["Section"]."' ";
$strSQL .=",Stream = '".$_POST["Stream"]."' ";
$strSQL .="BloodGroup = '".$_POST["BloodGroup"]."' ";
$strSQL .=",Nationality = '".$_POST["Nationality"]."' ";
$strSQL .=",Country = '".$_POST["Country"]."' ";
$strSQL .=",Religion = '".$_POST["Religion"]."' ";
$strSQL .=",MotherTongue = '".$_POST["MotherTongue"]."' ";
$strSQL .=",FirstLanguage = '".$_POST["FirstLanguage"]."' ";
$strSQL .="SecondLanguage = '".$_POST["SecondLanguage"]."' ";
$strSQL .=",PlaceOfBirth = '".$_POST["PlaceOfBirth"]."' ";
$strSQL .=",LandlineNumber = '".$_POST["LandlineNumber"]."' ";
$strSQL .=",EmailID = '".$_POST["EmailID"]."' ";
$strSQL .=",ChildPhoto = '".$_POST["ChildPhoto"]."' ";
$strSQL .=",TemporaryAddress = '".$_POST["TemporaryAddress"]."' ";
$strSQL .="PermanentAddress = '".$_POST["PermanentAddress"]."' ";
$strSQL .=",Mentor = '".$_POST["Mentor"]."' ";
$strSQL .=",DateOfJoin = '".$_POST["DateOfJoin"]."' ";
$strSQL .=",JoinGrade = '".$_POST["JoinGrade"]."' ";
$strSQL .=",ReferredBy = '".$_POST["ReferredBy"]."' ";
$strSQL .=",ContactNumber = '".$_POST["ContactNumber"]."' ";
$strSQL .="EmergencyContactNumber = '".$_POST["EmergencyContactNumber"]."' ";
$strSQL .="WHERE ChildID = '".$_GET["ChildID"]."' ";
$objQuery = mysql_query($strSQL);
if($objQuery)
{
echo "Save Done.";
}
else
{
echo "Error Save [".$strSQL."]";
}
mysql_close($objConnect);
?>
</body>
</html>
  • **Danger**: You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). You are also **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that a modern API would make it easier to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Apr 04 '14 at 06:10
  • As @Quentin said, migrate to MySQLi or PDO. MySQL method proved to be vulnerable. – Sarvap Praharanayuthan Apr 04 '14 at 06:16
  • What are the problems you are facing? – Sarvap Praharanayuthan Apr 04 '14 at 06:20
  • he is in all fiels Notice: Undefined variable: objResult in C:\xampp\htdocs\school\vijay\try1edit\phpMySQLEditRecordList.php on line 53. – user3317807 Apr 04 '14 at 06:26
  • the other is all fields on running another php.
    Notice: Undefined variable: objResult in C:\xampp\htdocs\school\vijay\try1edit\phpMySQLEditRecordForm.php on line 55
    – user3317807 Apr 04 '14 at 06:31

0 Answers0