PHP SQL表单 - 如何将值传递给下一个Select

Hi I have manage to put this script together as a newbe. I have divided the script up in two parts each part works individually, but when putting it together and when I make the WHERE as a changeable value it won't work.

(the reason for the line in error everywhere/shortcode.php(15) is because its running on a php wordpress plugin, but as I say the to parts works individual)

Can someone tell me how I can pass that value

$myvalue

and open the connection in part two of the script, without getting error on the connection part. The value do get past to the varible but makes an error.

Here is the errors I get:

Warning: mysqli_query(): Couldn't fetch mysqli in /home/asports/public_html/calendar/wp-content/plugins/php-everywhere/shortcode.php(15) : eval()'d code on line 34

Warning: mysqli_error(): Couldn't fetch mysqli in /home/asports/public_html/calendar/wp-content/plugins/php-everywhere/shortcode.php(15) : eval()'d code on line 52

ERROR: Could not able to execute SELECT men_slope FROM allcourses WHERE id='3'.

Warning: mysqli_close(): Couldn't fetch mysqli in /home/asports/public_html/calendar/wp-content/plugins/php-everywhere/shortcode.php(15) : eval()'d code on line 56

// part one

<?php 
require_once(
$_SERVER['DOCUMENT_ROOT'].'/calendar/courses/admin/connect.php'); 
?>
<form method=post>
<select name="myvalue">
<?php
// Attempt select query execution
$sql = "SELECT id, Name, color FROM allcourses";
$sql = mysqli_query($link, $sql);
while ($row = $sql->fetch_assoc()){
echo "<option value='".$row['id']."'>".$row['Name'] . " (" . $row['color']. 
")" . "</option>";

}
// Close connection
mysqli_close($link);
$myvalue=$_POST['myvalue'];
$myhdc=$_POST['hdc'];
?>
</select>
<br />
<p>Handicap: </p>
<input class="tex" type="text" name="hdc"\></input>

<br />

<input type=submit>
</form>

// Part two

<?php


// Attempt select query execution
$sqll = "SELECT men_slope FROM allcourses WHERE id='$myvalue'";
if($result = mysqli_query($link, $sqll)){
if(mysqli_num_rows($result) > 0){
while($row = mysqli_fetch_array($result)){
        echo "<tr>";

            echo "<td>" . $row['men_slope'] . "</td>";

        echo "</tr>";
    }

    // Free result set
    mysqli_free_result($result);
} else{
    echo "No records matching your query were found.";
}
} else{
echo "ERROR: Could not able to execute $sqll. " . mysqli_error($link);
}

// Close connection
mysqli_close($link);
?>

The problem is that you call mysqli_close($link); in Part One. Then when you try to perform a query in Part Two, the link is closed, so you can't use it any more.

IHMO, it's usually not important to call mysqli_close(). The connection will be closed automatically when the script ends. So unless your script runs for a long time after making all its database queries, it will not be idle for very long.