Page 1 of 1

Simple Enrollment for College Help

Posted: Mon Jan 09, 2012 7:19 am
by ShadowSkill
I made a simple Add and Search for my Enrollment
I named my database Eva with table info containing first, last, age, cp, email and course
This are my codings please help me Improve it i'm just a newbie at PHP and my cousin who is teaching me PHP just left for singapore.

Code: Select all

<html>
<head>

<title>Main</title>
</head>

<body>

<form action="reg.php" method="post">
First Name: <input type="text" name="first"><br>
Last Name: <input type="text" name="last"><br>
Cellphone #: <input type="text" name="cp"><br>
Age :<input type="text" name="age"><br>
E-mail: <input type="text" name="email"><br>
Course :<input type="text" name="course"><br>
<input type="Submit">
</form>

<?

$database="Eva";

$first=$_POST['first'];
$last=$_POST['last'];
$age=$_POST['age'];
$cp=$_POST['cp'];
$email=$_POST['email'];
$course=$_POST['course'];

mysql_connect("localhost","root", "");

@mysql_select_db($database) or die( "NO DATABASE");

$query = "INSERT INTO info VALUES('','$first','$last','$cp','$age','$email','$course')";
mysql_query($query);

mysql_close();

?>

</body>
</html>

Search Code

Posted: Mon Jan 09, 2012 7:24 am
by ShadowSkill
This is my Search PHP code please help me with the search code because i need to edit the searched first
name. The search function works but i need to put an Edit button to the results and then be able to edit the searched information.

Code: Select all

<!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=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<form action="edit.php" method="get">
Search: <input type="text" name="search">
<input type="hidden" name="searching" value="yes" />
<input type="Submit" value="Search" />
</form>

<?php


if( isset($_GET['search']))
{


  $first = @$_GET['search'] ;
  $trimmed = trim($first); 



$limit=10; 


if ($trimmed == "")
  {
  echo "<p>Please enter a search...</p>";
  exit;
  }


if (!isset($first))
  {
  echo "<p>We dont seem to have a search parameter!</p>";
  exit;
  }


mysql_connect("localhost","root","");


mysql_select_db("Eva") or die("Unable to select database"); 


$query = "select * from info where first like \"%$trimmed%\" "; 

 $numresults=mysql_query($query);
 $numrows=mysql_num_rows($numresults);


  if (empty($s)) {
  $s=0;
  }


  $query .= " limit $s,$limit";
  $result = mysql_query($query) or die("Couldn't execute query");


echo "<p>You searched for: "" . $first . ""</p>";


echo "Results : ";
	 echo " <br>";	
$count = 1 + $s ;

$result=mysql_query("SELECT *  FROM `info` WHERE `first` LIKE '%$first%'");



		while($row_array = mysql_fetch_array($result, MYSQL_ASSOC))
		{
			$first= $row_array['first'];		
			

	 
	 echo $row_array['first'];
	 echo " ";
	 echo $row_array['last'];
	 echo " ";
	 echo $row_array['age'];
	 echo " ";	 
	 echo $row_array['cp'];
	 echo " <br>";	 
	 
	 
	}

  while ($row= mysql_fetch_array($result)) {
  $title = $row["1st_field"];

  echo "$count.)&nbsp;$title". $first ;
  $count++ ;
  }

$currPage = (($s/$limit) + 1);


  echo "<br />";

 
  if ($s>=1) { // bypass PREV link if s is 0
  $prevs=($s-$limit);
  print "&nbsp;<a href=\"$PHP_SELF?s=$prevs&search=$first\"><< 
  Prev 10</a>&nbsp&nbsp;";
  }


  $pages=intval($numrows/$limit);



  if ($numrows%$limit) {
 
  $pages++;
  }


  if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {

  
  $news=$s+$limit;

  echo "&nbsp;<a href=\"$PHP_SELF?s=$news&search	=$first\">Next 10 >></a>";
  }

$a = $s + ($limit) ;
  if ($a > $numrows) { $a = $numrows ; }
  $b = $s + 1 ;
  echo "<p>Showing results $b to $a of $numrows</p>";
}
?>

<form action="index.php" method="post">
<input type="submit" name="Back" value="Back" />
</form>



</body>
</html>