ユーザーがクラブに個人情報を登録できるフォームがあり、データベースに保存されます。MySQLを含め、すべてが正常に機能しています。しかし、検索機能に問題があります。検索ページはスティッキーフォームである必要があります。ユーザーは結果を検索して表示できる必要があります...検索ボックスに名または姓を入力した場合と同様に、結果には特定の条件を満たすデータベースからのすべての情報が表示されます。私の検索機能を修正してくださいすべてのページコードは以下に与えられています....ありがとう!!!
これは私のフォームページコードです.....
<html>
<head>
<style type="text/css">
table
{
border-collapse:collapse;
border-color:#FFFFFF;
}
body
{
background-color:#39B3A7;
}
</style>
<?php
global $fname,$lname,$age,$gender,$course,$email;
if(!empty($_POST['register']))
{
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$age=$_POST['age'];
$gender=$_POST['gender'];
$course=$_POST['course'];
$email=$_POST['email'];
if (preg_match("/[a-zA-Z ]+$/", $_POST['fname'])) {
$fname = trim($_POST['fname']);
}
else
{
echo '<p>The First name is empty or has illegal characters! To edit please go the link Display Data Information</p>';
$error = true;
}
if (preg_match("/[a-zA-Z ]+$/", $_POST['lname'])) {
$lname = trim($_POST['lname']);
}
else
{
echo '<p>The last name is empty or has illegal characters! To edit please go the link Display Data Information</p>';
$error = true;
}
if(isset($_POST['age']))
{
$age=$_POST['age'];
}
else
{
echo "<p>Please enter your age</p>";
}
if(isset($_POST['gender']))
{
$gender = $_POST['gender'];
}
else
{
echo "<p>No gender found! So, we assume you are SHEMALE</p>";
}
if(isset($_POST['course']))
{
$course = $_POST['course'];
}
else
{
echo "<p>Please Select Course!</p>";
}
// Validate the email:
if (preg_match("/^[\w.-]+@[\w.-]+\.[A-Za-z]{2,6}$/", $_POST['email'] )){
$email = trim($_POST['email']);
}
else
{
echo '<p>The email is empty or has illegal characters! To edit please go the link Display Data Information</p>';
$error = true;
}
echo "<br/>";
echo "<br/>";
echo "<br/>";
}
if($fname&&$lname&&$age&&$gender&&$course&&$email)
{
require_once('connection.php');
$query = mysql_query("INSERT INTO members SET FirstName='$fname', LastName='$lname', Gender='$gender', Age='$age', Email='$email', Course='$course'") or die(mysql_error());
if($query){
echo"Your Data Successfully Saved";
}
else
{
echo "Please recheck your Data!";
}
}
?>
</head>
<body>
<h2><strong>Register Student Account</strong></h2>
<form action="student_form.php" method="post" >
<table border="1">
<tr>
<td>First Name</td>
<td>:</td>
<td><input type="text" name="fname" size="30" maxlength="50"/></td>
</tr>
<tr>
<td>Last Name</td>
<td>:</td>
<td><input type="text" name="lname" size="30" maxlength="50"/></td>
</tr>
<tr>
<td>Age</td>
<td>:</td>
<td><input type="text" name="age" size="3" /></td>
</tr>
<tr>
<td >Gender </td>
<td> : </td>
<td> Male
<input type="radio" name="gender" value="Male"/>
Female
<input type="radio" name="gender" value="Female"/></td>
</tr>
<tr>
<td valign="top">Course</td>
<td valign="top"> : </td>
<td> <input type="radio" name="course" value="Bachelor Of Computing"/>Bachelor Of Computing<br/>
<input type="radio" name="course" value="Bachelor Of Science"/>Bachelor Of Science<br/>
<input type="radio" name="course" value="Bachelor Of Software Engineering"/>Bachelor Of Software Engineering<br/>
<input type="radio" name="course" value="Bachelor Of Networking"/>Bachelor Of Networking<br/>
<input type="radio" name="course" value="Bacelor Of IT"/>Bacelor Of IT <br/>
<input type="radio" name="course" value="Bachelor Of Computer Science"/>Bachelor Of Computer Science</td>
</tr>
<tr>
<td>Email Address</td>
<td>:</td>
<td><input type="text" name="email" size="30" maxlength="50"/></td>
</tr>
</table>
<input type="submit" name="register" value="REGISTER"/>
</form><br>
<p><a href="student_form.php" >Home</a></p>
<p><a href="display_data.php">Display Data Information</a>
<p><a href="search.php">To search for Members</a>
</body>
</html>
これは私の接続ページコードです。
<?php
$username = "root";
$password = "";
$con = mysql_connect('localhost',$username,$password) or die(mysql_error());
$db=mysql_select_db("taylor");
?>
これは私のdisplay_dataコードです...
<html>
<head>
<style type="text/css">
table
{
border-collapse:collapse;
border-color:#FFFFFF;
}
body
{
background-color:#39B3A7;
}
</style>
</head>
<body>
<table border="1">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<th>Age</th>
<th>Gender</th>
<th>Course</th>
<th>Action</th>
</tr>
<?php
include('connection.php');
$query=mysql_query("SELECT * FROM members");
while($rows=mysql_fetch_array($query)){
?>
<tr>
<td><?php echo $rows['FirstName']; ?></td>
<td><?php echo $rows['LastName']; ?></td>
<td><?php echo $rows['Email']; ?></td>
<td><?php echo $rows['Age']; ?></td>
<td><?php echo $rows['Gender']; ?></td>
<td><?php echo $rows['Course']; ?></td>
<td>
<a href="edit.php?id=<?php echo $rows['Id']; ?>">Edit</a>
<a href="delete.php?id=<?php echo $rows['Id']; ?>">Delete</a>
</td>
</tr>
<?php
}
?>
</table>
<p><a href="student_form.php">Home</a></p>
</body>
</html>
これは私の
これは私の検索ページコードです。
<html>
<head>
<?php
//require_once('student_form.php');
if(isset($_POST['submit'])){
$id=$_REQUEST['id'];
$fname=$_POST['fname'];
//connect to the database
include('connection.php');
//-query the database table
$sql="SELECT * FROM members WHERE FirstName=" . $fname;
//-run the query against the mysql query function
$result=mysql_query($sql);
while($row=mysql_fetch_array($result)){
$fname=$row['FirstName'];
$lname=$row['LastName'];
$email=$row['Email'];
$age =$row['Age'];
$gender=$row['Gender'];
$course = $row['Course'];
//-display the result of the array
echo "<ul>\n";
echo "<li>" . $fname . " " . $lname . "</li>\n";
echo "<li>" . $email . "</li>\n";
echo "<li>" . $age . "</li>\n";
echo "<li>" . $gender . "</li>\n";
echo "<li>" . $course . "</li>\n";
echo "</ul>";
}
}
?>
</head>
<body>
<form action="search.php" method="post">
<table>
<tr>
<td><strong>search box</strong></td>
<td><strong>:</strong></td>
<td><input type="text" name="search" value="Enter First Name of The member"size="30"/><input type="submit" value="Search"/></td>
</table>
</form>
</body>
</html>