<?php
$hostname = "****"; //name of the server
$username = "***"; //id of the user
$password = "****"; //password of the user
$db = "**"; //name of the database
//connect to the database
$conn = mysql_connect($hostname,$username,$password);
if (!$conn) {
die("Could not connect: " . mysql_error());
}
//select the database
$db_selected = mysql_select_db($db, $conn);
if (!$db_selected) {
die ("Can\"t use " . $db . mysql_error());
}
echo "<form action='Assign6next.php' method=\"post\">";
$sql= "SELECT * FROM Author"; //This selects all columns from author
echo "Author List"; //Echo name
echo "<br>";
$result= mysql_query($sql, $conn); //The result of the query in database
echo '<select name="AuthorName"><OPTION>';//Creates dropdown for Author dropdown
echo "Select an Author</OPTION>"; //
echo "<br>";
while ($row = mysql_fetch_array($result)){ //While in the loop return results in row
$last= $row["AuthorLast"]; //Create variable last for Last Names
$first = $row["AuthorFirst"]; //Create variables for first Names
echo "<OPTION value=$last,$first>$last,$first</OPTION>";
}
echo '</SELECT>'; //End of drop down list
echo "<br>";
echo "<INPUT type='submit' value='Get Titles' name='submit'>";
if (isset($_POST['submit']))
{
//echo "button 1 has been pressed";
$auth = $_POST['AuthorName'];
//echo $auth;
//echo "<br>";
//$data = "foo:*:1023:1000::/home/foo:/bin/sh";
list($lastn, $firstn) = explode(",", $auth);
echo "<input type='hidden' name='lname' value=$lastn>";
//echo "</INPUT>";
//echo '<input type="hidden" name="lname" value="'.$lastn.'">';
//echo '<input type="hidden" name="lname" value="' . htmlspecialchars($lastn) . '">';
//$_COOKIE['lname'] = $lastn;
//echo $lastn;
//echo "<br>";// foo
//echo $firstn; // *
}
echo "</form>";
///////
//close the connection to MySQL
mysql_close($conn);
?>
上記のコードでは、 $lastn に姓の文字列があり、これを隠し変数として別のページに渡しています。
<?php
$lastn = $_POST['lname'];
echo $lastn;
echo "string";
?>
上記のコードを使用して隠し変数をキャッチしようとしていますが、「文字列」のみが表示され、前のページから取得した姓は表示されません。