Jump to content

Switch Help


mayman212

Recommended Posts

<!--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'];

mysql_query("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>&nbsp&nbsp<a href='switch.php?action=delete&id=" . $row['ID']."'>Delete</a></td>";
	  echo "</tr>";
	  }
	echo "</table>";

	echo "<a href='switch.php?action=write'>Insert</a>";



}

mysql_close($con);
?>

Here is the completed code, but I still have a problem the page is coming up with an error:

 

 

 

( ! ) Fatal error: Cannot break/continue 1 level in C:\wamp\www\p1\switch.php on line 63

Call Stack

# Time Memory Function Location

1 0.0009 413960 {main}( ) ..\switch.php:0

 

I cannot seem to figure it out, Can anyone help?

Thanks

Link to comment
Share on other sites

<!--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'];

mysql_query("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#################



$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':
       $id= $_GET['id'];
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>&nbsp&nbsp<a href='switch.php?action=delete&id=" . $row['ID']."'>Delete</a></td>";
	  echo "</tr>";
	  }
	echo "</table>";

	echo "<a href='switch.php?action=write'>Insert</a>";



}

mysql_close($con);
?>

Link to comment
Share on other sites

You have bad parenthesis around you conditionals within your switch case. here it is cleaned up:

 

<?php
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'];
	mysql_query("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;
}
?>

 

 

Use proper indentation in your code. It makes it much clearer to see where you have made an error.

Link to comment
Share on other sites

Here is the up to date code:

<!--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>&nbsp&nbsp<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);
?>
[/close]

Link to comment
Share on other sites

i dont think that the the action like your doing is going to to work, from your code:

 

 <form action="switch.php?id=<?php echo $row['ID']?> action=edit_ok" method="post"> 

 

try this way add something like this in your form:

 

<form action="switch.php" method="post">
<input type='hidden' name='action' value='edit_ok'>
(...)
</form>

 

On the switch use $_POST['action'], i was testing out this today and this is how i made my code to work hope it helps...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.