搜索用户特定信息


Search User Specific information

PHP新手,请具体说明。一旦我的用户登录,他们就会来到一个表单来提交数据。我希望用户能够搜索过去一个月输入的关于他们的所有数据。如果他们愿意,可以从中进行编辑或删除。请告诉我这次搜索使用什么代码。以下是我所拥有的(搜索根本不起作用)

    <h1>Welcome!</h1>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
Search: <input type="text" name="search">
<input type="submit" value="submit">
    </form> 

    <?php
// Check if the form value
// was submitted, if not
// assign a default value
if(isset($_GET['search'])){
    $s = $_GET['search'];
}else{
    $s = "%";
}

//echo $s;
// Connects to the database
mysql_connect("localhost","sample","qwerty") or die("Error " . mysqli_error($link));
// Selects which of the databases to use
mysql_select_db('crm');
// Create and runs the query
$sql = "SELECT * FROM hours WHERE employee_id LIKE 'RHilfi'";
//echo $sql;
$results = mysql_query($sql);

echo "<br /><br />";
// Loops though all of the results
while($results_array = mysql_fetch_array($results)){
    /*
    echo "<pre>";
    print_r($results_array);
    echo "</pre>";
    */
    //print_r($results_array);
    echo " Employee ID: " . $results_array['employee_id'] . " , Date: " .      $results_array['date'] . " , Rate of Pay: " . $results_array['rate_of_pay'] . " , Hours: " . $results_array['hours'] ." , Amount Due: " . $results_array['amount_due']. " [ <a href='"edit.php?id=" . $results_array['hours'] . "'">EDIT</a>]";
    /*
    // USE THIS ONE
    echo $results_array['title'] . " by " . $results_array['director'] . " [ <a href='"edit.php?id=" . $results_array['hours'] . "'">EDIT</a>]";
    */

    echo "<br />";
}
    ?>
    <h1>Submit New Claim</h1>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
Employee ID: <input type="text" name="employee_id">
<br />
Date (yyyy/mm/dd): <input type="text" name="date">
<br />
Rate of Pay: <input type="text" name="rate_of_pay">
<br />
    Hours: <input type="text" name="hours">
<br />
    Amount Due: <input type="text" name="amount_due">
<br />
<input type="submit" value="Submit">
    </form> 

    <?php

if(isset($_GET['employee_id'])){
    $employee_id = $_GET['employee_id'];
    $date = $_GET['date'];
    $rate_of_pay = $_GET['rate_of_pay'];
    $hours = $_GET['hours'];
    $amount_due = $_GET['amount_due'];
}else{
    $employee_id = "";
    $date = "";
    $rate_of_pay = "";
    $hours = "";
    $amount_due = "";
}

if(isset($_GET['employee_id'])){
    //echo "INSERT NEW RECORD";
    // INSERT NEW RECORD
    // Connects to the database
    mysql_connect("localhost","sample","qwerty") or die("Error " .  mysqli_error($link));
    // Selects which of the databases to use
    mysql_select_db('crm');
    // Create and runs the query
    // INSERT INTO `sample`.`dvd` (`dvd_id`, `title`, `year`, `director`) VALUES  (NULL, 'title', '1234', 'director'); 
    //$sql = "INSERT INTO crm . 'hours' (employee_id, date, rate_of_pay, hours, amount_due) VALUES (NULL, '$employee_id', '$date', '$rate_of_pay', '$hours', $amount_due)";
    $sql = "INSERT INTO hours (ID, employee_id, date, rate_of_pay, hours, amount_due) VALUES (NULL, '$employee_id', '$date', '$rate_of_pay', '$hours', $amount_due)";
    //echo $sql;
    $results = mysql_query($sql);
    echo "<br /><br />";

    // OPTIONAL
    if(mysql_affected_rows() >= 1){
        echo "<h3>Thank you! You have successfully submitted a claim </h3>";
    }
}
    ?>

<a href="login.php">Log Out</a>

使用mysqli,如果您在MySQL中使用LIKE,则会使其看起来像这样:

$sql = "SELECT * FROM hours WHERE employee_id LIKE '%RHilfi%'";