這是一個教科書問題,其中我遵循了確切的編碼。然而我一直在收集未定義指數和未定義可變因素的錯誤。我繼續研究我的代碼,我想我錯過了疲勞的錯誤。這是代碼。有什麼建議麼。我反對時鐘。這裏是htm file associated with this。在php中未定義的索引和變量
以下是錯誤消息:
Undefined index: firstname in D:\Inetpub\Ciswebs\CIS54\TYSON_SCHWEIDEL\cReport.php on line 10 PHP Notice: Undefined index: lastname in D:\Inetpub\Ciswebs\CIS54\TYSON_SCHWEIDEL\cReport.php on line 11 PHP Notice: Undefined index: whenithappened in D:\Inetpub\Ciswebs\CIS54\TYSON_SCHWEIDEL\cReport.php on line 12 PHP Notice: Undefined index: howlong in D:\Inetpub\Ciswebs\CIS54\TYSON_SCHWEIDEL\cReport.php on line 13 PHP Notice: Undefined index: howmany in D:\Inetpub\Ciswebs\CIS54\TYSON_SCHWEIDEL\cReport.php on line 14 PHP Notice: Undefined index: aliendescription in D:\Inetpub\Ciswebs\CIS54\TYSON_SCHWEIDEL\cReport.php on line 15 PHP Notice: Undefined index: whattheydid in D:\Inetpub\Ciswebs\CIS54\TYSON_SCHWEIDEL\cReport.php on line 16 PHP Notice: Undefined index: fangspotted in D:\Inetpub\Ciswebs\CIS54\TYSON_SCHWEIDEL\cReport.php on line 17 PHP Notice: Undefined index: email in D:\Inetpub\Ciswebs\CIS54\TYSON_SCHWEIDEL\cReport.php on line 18 PHP Notice: Undefined index: other in D:\Inetpub\Ciswebs\CIS54\TYSON_SCHWEIDEL\cReport.php on line 19 PHP Notice: Undefined variable: name in D:\Inetpub\Ciswebs\CIS54\TYSON_SCHWEIDEL\cReport.php on line 33
<!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>Alien Abduction2</title>
</head>
<body>
<?php
$first_name = $_POST['firstname'];
$last_name = $_POST['lastname'];
$when_it_happened = $_POST['whenithappened'];
$how_long = $_POST['howlong'];
$how_many = $_POST['howmany'];
$alien_description = $_POST['aliendescription'];
$what_they_did = $_POST['whattheydid'];
$fang_spotted = $_POST['fangspotted'];
$email = $_POST['email'];
$other = $_POST['other'];
$dbc = mysqli_connect('localhost','cis54student','student','cis54')
or die('Error connecting to MySQL server');
$query = "INSERT INTO aliens_abduction (first_name, last_name, when_it_happened, how_long, " .
"how_many, alien_description, what_they_did, fang_spotted, other, email) " .
"VALUES ('$first_name', '$last_name', '$when_it_happened', '$how_long', '$how_many', " .
"'$alien_description', '$what_they_did', '$fang_spotted', '$other', '$email')";
$result = mysqli_query($dbc, $query)
or die('Error querying database.' . mysqul_error());
mysqli_close($dbc);
echo "Thanks for submitting the form $name<br />";
echo "You were abducted ' $when_it_happened<br />";
echo "And were gone for ' . $how_long <br />";
echo "Number of aliens: ' . $how_many <br />";
echo "Describe them: ' . $alien_description <br />";
echo "The aliens did this: $what_they_did <br />";
echo "Was Fang there? $fang_spotted <br />";
echo "Other comments: ' . $other <br />";
echo 'Your email address is ' . $email;
?>
</body>
</html>
當心SQL注入的,你的代碼是脆弱的。 –
確切的錯誤信息會有幫助 – Chris
這些是調試通知。不調試時關閉它們。那裏確實存在更大的問題。把這本教科書扔掉,如果它是一個例子。還有另一個錯字:'PHP致命錯誤:調用未定義的函數mysqul_error()' – mario