<!--PHP Update-->
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("project1", $con);
if ($_GET['action']=='delete_ok'){
}elseif ($_GET['action']=='edit_ok'){
}
switch($_GET['action']){
case 'write_ok':
$sql = "INSERT INTO project_data (Date_Of_Birth, Gender, Title, First_Name, Last_Name, Address_Line_1, Address_Line_2, City, Postcode, Contact_No, Email, Additional_Comment) VALUES ('".$_POST[dateofbirth]."','".$_POST[gender]."','".$_POST[title]."','".$_POST[firstname]."','".$_POST[lastname]."','".$_POST[address1]."','".$_POST[address2]."','".$_POST[city]."','".$_POST[postcode]."','".$_POST[contactno]."','".$_POST[email]."','".$_POST[note]."')";
if(!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
else{
echo '<script>alert("Data Has Been Successfully Updated");</script>';
echo '<meta http-equiv="Refresh" content="0;URL=switch.php">';
}
break;
case 'edit_ok':
if((!isset($_GET['id']) || trim($_GET['id']) == '')) {
die('Missing record ID!');
}
$id = $_GET['id'];
$sql = ("UPDATE project_data SET Date_Of_Birth='".$_POST[dateofbirth]."',Gender='".$_POST[gender]."',Title='".$_POST[title]."',First_Name='".$_POST[firstname]."',Last_Name='".$_POST[surname]."',Address_Line_1='".$_POST[address1]."',Address_Line_2='".$_POST[address2]."',City='".$_POST[city]."',Postcode='".$_POST[postcode]."',Contact_No='".$_POST[contactno]."',Email='".$_POST[email]."',Additional_Comment='".$_POST[note]."' WHERE ID='".$_GET['id']. "'") or die ("Error in query: $query. " . mysql_error());
echo '<script>alert("Data Has Been Successfully Updated");</script>';
echo '<meta http-equiv="Refresh" content="0;URL=switch.php">';
break;
case 'delete_ok':
#########Delete OK Start#################
$id= $_GET['id'];
$result = mysql_query("DELETE FROM project_data WHERE ID = '$id'") or die ("Error in query: $query. " . mysql_error());
echo '<script>alert("Data Has Been Successfully Updated");</script>';
echo '<meta http-equiv="Refresh" content="0;URL=switch.php">';
#########Delete OK End #################
break;
}
?>
<!--HTML-->
<?php
switch($_GET['action']){
case 'delete':
break;
case 'edit':
echo 'Edit page';
?>
<?php
$id=$_GET['id'];
$result = mysql_query("SELECT * FROM project_data WHERE id='$id'");
$row = mysql_fetch_array($result);
?>
<table border = "1">
<form action="switch.php?id=<?php echo $row['ID']?> action=edit_ok" method="post">
<tr>
<td>Date Of Birth</td>
<td><input type="text" name="dateofbirth" value="<?php echo $row['Date_Of_Birth']?>"/></td>
</tr>
<tr>
<td>Gender</td>
<td><input type="radio" name="gender" value="male" <?php if($row['Gender']=='male'){echo 'checked';}?>/> Male<input type="radio" name="gender" value="female" <?php if($row['Gender']=='female'){echo 'checked';}?>/> Female</td>
</tr>
<tr>
<td>Title</td>
<td><select name="title">
<option value="">Please Select</option>
<option value="Mr" <?php if($row['Title']=='Mr'){echo 'selected';}?>>Mr</option>
<option value="Ms" <?php if($row['Title']=='Ms'){echo 'selected';}?>>Ms</option>
<option value="Mrs" <?php if($row['Title']=='Mrs'){echo 'selected';}?>>Mrs</option>
<option value="Miss" <?php if($row['Title']=='Miss'){echo 'selected';}?>>Miss</option>
<option value="Other" <?php if($row['Title']=='Other'){echo 'selected';}?>>Other</option>
</select></td>
</tr>
<tr>
<td>First Name</td>
<td><input type="text" name="firstname" value="<?php echo $row['First_Name']?>"/></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type="text" name="lastname" value="<?php echo $row['Last_Name']?>" /></td>
</tr>
<tr>
<td>Address Line 1</td>
<td><input type="text" name="address1" value="<?php echo $row['Address_Line_1']?>" /></td>
</tr>
<tr>
<td>Address Line 2</td>
<td><input type="text" name="address2" value="<?php echo $row['Address_Line_2']?>" /></td>
</tr>
<tr>
<td>City</td>
<td><input type="text" name="postcode" value="<?php echo $row['City']?>" /></td>
</tr>
<tr>
<td>Postcode</td>
<td><input type="text" name="postcode" value="<?php echo $row['Postcode']?>" /></td>
</tr>
<tr>
<td>Contact No</td>
<td><input type="text" name="contactno" value="<?php echo $row['Contact_No']?>" /></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email" value="<?php echo $row['Email']?>"/></td>
</tr>
<tr>
<td>Additional Info</td>
<td><textarea rows="10" cols="30" name="note"><?php echo $row['Additional_Comment']?></textarea></td>
</tr>
<tr>
<td><input type="submit" value="Edit" /></td>
<td><a href='switch.php'>Back</a></td>
</tr>
</table>
</form>
<?php
break;
case 'write';
?>
<form action="switch.php?action=write_ok" method="post">
<table>
<tr>
<td>Date Of Birth</td>
<td><input type="text" name="dateofbirth" /></td>
</tr>
<tr>
<td>Gender</td>
<td><input type="radio" name="gender" value="male" />Male<input type="radio" name="gender" value="female" /> Female</td>
</tr>
<tr>
<td>Title</td>
<td><select name="title">
<option value="" selected="selcted">Please Select</option>
<option value="Mr">Mr</option>
<option value="Mrs">Mrs</option>
<option value="Miss">Miss</option>
<option value="Ms">Ms</option>
<option value="Other">Other</option>
</select></td>
</tr>
<tr>
<td>First Name</td>
<td><input type="text" name="firstname" /></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type="text" name="lastname" /></td>
</tr>
<tr>
<td>Address Line 1</td>
<td><input type="text" name="address1" /></td>
</tr>
<tr>
<td>Address Line 2</td>
<td><input type="text" name="address2" /></td>
</tr>
<tr>
<td>City</td>
<td><input type="text" name="city" /></td>
</tr>
<tr>
<td>Postcode</td>
<td><input type="text" name="postcode" /></td>
</tr>
<tr>
<td>Contact No</td>
<td><input type="text" name="contactno" /></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email" /></td>
</tr>
<tr>
<td>Additional Info</td>
<td><textarea rows="15" cols="30" name="note">Please Enter Any Additional Information</textarea></td>
</tr>
<tr>
<td><input type="submit" value="Submit"></td>
<td><a href='switch.php'>Back</a></td>
</tr>
</table>
</form>
<?php
break;
default:
echo "<table border='1'>
<tr>
<th>ID</th>
<th>Date Of Birth</th>
<th>Gender</th>
<th>Title</th>
<th>First Name</th>
<th>Last Name</th>
<th>Address Line 1</th>
<th>Address Line 2</th>
<th>City</th>
<th>Postcode</th>
<th>Contact No</th>
<th>Email</th>
<th>Additional Info</th>
<th>Action</th>
</tr>";
$result = mysql_query("SELECT * FROM project_data");
while($row = mysql_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['ID'] . "</td>";
echo "<td>" . $row['Date_Of_Birth'] . "</td>";
echo "<td>" . $row['Gender'] . "</td>";
echo "<td>" . $row['Title'] . "</td>";
echo "<td>" . $row['First_Name'] . "</td>";
echo "<td>" . $row['Last_Name'] . "</td>";
echo "<td>" . $row['Address_Line_1'] . "</td>";
echo "<td>" . $row['Address_Line_2'] . "</td>";
echo "<td>" . $row['City'] . "</td>";
echo "<td>" . $row['Postcode'] . "</td>";
echo "<td>" . $row['Contact_No'] . "</td>";
echo "<td>" . $row['Email'] . "</td>";
echo "<td>" . $row['Additional_Comment'] . "</td>";
echo "<td><a href='switch.php?action=edit&id=" . $row['ID']."'>Edit</a>  <a href='switch.php?action=delete_ok&id=" . $row['ID']."'>Delete</a></td>";
echo "</tr>";
}
echo "</table>";
echo "<a href='switch.php?action=write'>Insert</a>";
}
mysql_close($con);
?>
here is a code for a page. But the problem with it is that the edit_ok part which is supposed to process and execute the update part does'nt seem to be working, it just goes back to the default part with no changes. And also the delete part does not work at all, just leads to a blank page.
Any help would be appreciated.
thanks