Jump to content

comment page (forum style)


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':
case 'edit_ok':
case 'comment_ok';

$error=false;

$msg='';

if($_POST['dateofbirth']=='' || !preg_match( "/^(19|20)\d\d[- \\.](0[1-9]|1[012])[- \\.](0[1-9]|[12][0-9]|3[01])$/",$_POST['dateofbirth'])){
	$error=true;
	$msg.='Date of birth is required and in the correct format 0000.00.00\n';

}


   if($_POST['gender']==''){
	$error=true;
	$msg.='Gender is a required field\n';

}


if($_POST['title']==''){
	 $error=true;
	 $msg.='Please select your title\n';
}


if($_POST['firstname']==''){
	 $error=true;
	 $msg.='Please Enter your First Name\n';
}


if($_POST['lastname']==''){
	 $error=true;
	 $msg.='Please Enter your Last Name\n';
}


if($_POST['address1']==''){
	 $error=true;
	 $msg.='Please Enter the first line of your address\n';
}


if($_POST['city']==''){
	 $error=true;
	 $msg.='Please Enter your city of residence\n';
}


   if($_POST['postcode']==''|| !preg_match( "/^([A-PR-UWYZ0-9][A-HK-Y0-9][AEHMNPRTVXY0-9]?[ABEHMNPRVWXY0-9]? {1,2}[0-9][ABD-HJLN-UW-Z]{2}|GIR 0AA)$/",$_POST['postcode'])){
	 $error=true;
	 $msg.='Please Enter a Valid Postcode\n';
}


if($_POST['contactno']==''|| !preg_match( "/^((\+44\s?\d{4}|\(?\d{5}\)?)\s?\d{6})|((\+44\s?|0)7\d{3}\s?\d{6})$/",$_POST['contactno'])){
	 $error=true;
	 $msg.='Please Enter your Contact No\n';
}


if($_POST['email']==''|| !preg_match( "/^([a-z0-9])(([-.]|[]+)?([a-z0-9]+))(@)([a-z0-9])((([-]+)?([a-z0-9]+))?)*((.[a-z]{2,3})?(.[a-z]{2,6}))$/",$_POST['email'])){
	 $error=true;
	 $msg.='Please Enter a Valid Email Address\n';
}

if($error){

	echo '<script>alert("'.$msg.'");history.back()</script>';
//			echo '<meta http-equiv="Refresh" content="0;URL=pv.php?action=write">';
}else{

	if ($_GET['action']=='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=pv.php">';
		}

	}elseif($_GET['action']=='edit_ok'){

		$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[lastname]."',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=pv.php">';


	}elseif($_GET['action']=='comment_ok'){













	}
}


break;

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=pv.php">';
	#########Delete OK End #################
break;









break;
}
?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>pv.php</title>

<link rel="stylesheet" type="text/css" media="screen" href="css/screen.css" />

<style type="text/css">
#commentForm { width: 500px; }
#commentForm label { width: 250px; }
#commentForm label.error, #commentForm input.submit { margin-left: 253px; color:red;}

.paginate {
font-family:Arial, Helvetica, sans-serif;
padding: 3px;
margin: 3px;
}

.paginate a {
padding:2px 5px 2px 5px;
margin:2px;
border:1px solid #999;
text-decoration:none;
color: #666;
}
.paginate a:hover, .paginate a:active {
border: 1px solid #999;
color: #000;
}
.paginate span.current {
    margin: 2px;
padding: 2px 5px 2px 5px;
	border: 1px solid #999;

	font-weight: bold;
	background-color: #999;
	color: #FFF;
}
.paginate span.disabled {
	padding:2px 5px 2px 5px;
	margin:2px;
	border:1px solid #eee;
	color:#DDD;
}

li{
	padding:4px;
	margin-bottom:3px;
	background-color:#FCC;
	list-style:none;}

ul{margin:6px;
padding:0px;}

</style>

</head>
<body>



<?php

switch($_GET['action']){
case 'delete':
      
break;
case 'edit':
case 'write':
case 'comment':


  if($_GET['action']=='edit'){
		$form_action = 'edit_ok';
		echo 'Edit Page';
  }else{
		$form_action = 'write_ok';
		echo ''; 
  
  }

      if($_GET['action']=='comment'){
	 $form_action = 'comment_ok';
         echo 'New Comment';
         






 }


	?>
<?php
$id=$_GET['id'];
$result = mysql_query("SELECT * FROM project_data WHERE id='$id'");
$row = mysql_fetch_array($result);
?>

<form method="post" action="pv.php?id=<?php echo $row['ID']?>&action=<?php echo $form_action ?>">
<fieldset>
	<legend></legend>
	<p>
		<label for="cname">Date Of Birth</label>  *
		<input id="cname" name="dateofbirth" class="required date"  value="<?php echo $row['Date_Of_Birth']?>" />  (eg 1978.11.11)
	</p>
	<p>
		<label for="cgender">Gender</label>   *
		<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>
	</p>
	<p>
		<label for="curl">Title</label>   *
		<select name="title"   id="title"  class="required">
			<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>
	</p>
	<p>
		<label for="ccomment">First Name</label>     *
		<input type="text" name="firstname" value="<?php echo $row['First_Name']?>" maxlength="50" />
	</p>


	<p>
	<label for="cemail">Last Name</label> *
		<input id="cemail" type="text" name="lastname" value="<?php echo $row['Last_Name']?>" maxlength="75" />
       </p>
	<p>
		<label for="ccomment">Address 1</label>*
		<input type="text" name="address1" value="<?php echo $row['Address_Line_1']?>" maxlength="50" />  
	</p>
	<p>
		<label for="ccomment">Address 2</label>
		<input type="text" name="address2" value="<?php echo $row['Address_Line_2']?>" maxlength="50" />
	</p>
	<p>
		<label for="ccomment">City</label>*
		<input type="text" name="city" value="<?php echo $row['City']?>"  maxlength="50" />
	</p>
	<p>
		<label for="ccomment">Postcode</label>*
		<input type="text" name="postcode" value="<?php echo $row['Postcode']?>" maxlength= "10" />  (eg LE5 5QE)
	</p>
	<p>
		<label for="ccomment">Contact No</label>*
		<input type="text" name="contactno" value="<?php echo $row['Contact_No']?>" maxlength= "12" />  (eg 077448825723)
	</p>
	<p>
		<label for="ccomment">Email</label>*
		<input type="text" name="email" value="<?php echo $row['Email']?>" maxlength= "40"/>  (eg info@example.com)
	</p>
	<p>
		<label for="ccomment">Comment</label>
		<textarea rows="10" cols="30" name="note"  maxlength= "500"><?php echo $row['Additional_Comment']?></textarea>
	</p>
	<p>
		<input class="submit" type="submit" value="Submit"/>
	</p>
	<p>
	<a href='pv.php'>Main Page</a>
   </p>

</fieldset>
</form>



                


	<?php


		break;

		//case 'write';
	?>
          <!--<table border = "1">
	  <form action="pv.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='pv.php'>Back</a></td>
		</tr>
	  </table>
	  </form>-->

<?php

//break;
default:


?>


<style type="text/css">

</style>


<?php

	echo "<table border='1'>
	<tr bgcolor ='#FFFACD'>
	<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>";

        







$tbl_name="project_data";		//your table name
// How many adjacent pages should be shown on each side?
$adjacents = 1;

/* 
   First get total number of rows in data table. 
   If you have a WHERE clause in your query, make sure you mirror it here.
*/
$query = "SELECT COUNT(*) as num FROM $tbl_name";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages[num];

/* Setup vars for query. */
$targetpage = "pv.php"; 	//your file name  (the name of this file)
$limit = 3; 								//how many items to show per page
$page = $_GET['page'];
if($page) 
	$start = ($page - 1) * $limit; 			//first item to display on this page
else
	$start = 0;								//if no page var is given, set start to 0

/* Get data. 

order by ?

group
parent
level



*/
$sql = "SELECT * FROM project_data LIMIT $start, $limit";
$result = mysql_query($sql);

/* Setup page vars for display. */
if ($page == 0) $page = 1;					//if no page var is given, default to 1.
$prev = $page - 1;							//previous page is page - 1
$next = $page + 1;							//next page is page + 1
$lastpage = ceil($total_pages/$limit);		//lastpage is = total pages / items per page, rounded up.
$lpm1 = $lastpage - 1;						//last page minus 1

/* 
	Now we apply our rules and draw the pagination object. 
	We're actually saving the code to a variable in case we want to draw it more than once.
*/
$pagination = "";
if($lastpage > 1)
{	
	$pagination .= "<div class=\"pagination\">";
	//previous button
	if ($page > 1) 
		$pagination.= " <a href=\"$targetpage?page=$prev\">« previous</a> ";
	else
		$pagination.= " <span class=\"disabled\">« previous</span> ";	

	//pages	
	if ($lastpage < 7 + ($adjacents * 2))	//not enough pages to bother breaking it up
	{	
		for ($counter = 1; $counter <= $lastpage; $counter++)
		{
			if ($counter == $page)
				$pagination.= " <span class=\"current\">$counter</span >";
			else
				$pagination.= " <a href=\"$targetpage?page=$counter\">$counter</a> ";					
		}
	}
	elseif($lastpage > 5 + ($adjacents * 2))	//enough pages to hide some
	{
		//close to beginning; only hide later pages
		if($page < 1 + ($adjacents * 2))		
		{
			for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
			{
				if ($counter == $page)
					$pagination.= " <span class=\"current\">$counter</span> ";
				else
					$pagination.= " <a href=\"$targetpage?page=$counter\">$counter</a> ";					
			}
			$pagination.= "...";
			$pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
			$pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";		
		}
		//in middle; hide some front and some back
		elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
		{
			$pagination.= "<a href=\"$targetpage?page=1\">1</a>";
			$pagination.= "<a href=\"$targetpage?page=2\">2</a>";
			$pagination.= "...";
			for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
			{
				if ($counter == $page)
					$pagination.= "<span class=\"current\">$counter</span>";
				else
					$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";					
			}
			$pagination.= "...";
			$pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
			$pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";		
		}
		//close to end; only hide early pages
		else
		{
			$pagination.= "<a href=\"$targetpage?page=1\">1</a>";
			$pagination.= "<a href=\"$targetpage?page=2\">2</a>";
			$pagination.= "...";
			for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
			{
				if ($counter == $page)
					$pagination.= "<span class=\"current\">$counter</span>";
				else
					$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";					
			}
		}
	}

	//next button
	if ($page < $counter - 1) 
		$pagination.= "<a href=\"$targetpage?page=$next\">next »</a>";
	else
		$pagination.= "<span class=\"disabled\">next »</span>";
	$pagination.= "</div>\n";		
}









	//$result = mysql_query("SELECT * FROM $tbl_name");
	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='pv.php?action=edit&id=" . $row['ID']."'>Edit</a>&nbsp&nbsp<a href='pv.php?action=delete_ok&id=" . $row['ID']."'>Delete</a>&nbsp&nbsp<a href='pv.php?action=comment'>Comment</a></td>";
	  echo "</tr>";
	  }
	echo "</table>";

	echo $pagination;

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



}

mysql_close($con);

?>

</body>
</html>

 

I have a link which is for a comment page, it takes me to a blank form when I click it on the current record. But what I want it to do is show the record that i clicked on, to show at the top of the page, my mind has gone completely blank.

 

if($_GET['action']=='comment'){
	 $form_action = 'comment_ok';
         echo 'should be something here';

 

Anyone have any idea?

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.