次のエラー メッセージが表示されました。
注意: 未定義の変数: location1 の /home/students/accounts///www/htdocs/jobassign1b/jobsprocess.php 行 126
エラーメッセージは、以下のphpコードを見ると、この行にあります
if (fwrite($jobTxt, $positionID . " " . $title . " " . $description . " " . $positionButton . " " . $contractButton . " " . $location1 . " " . $date . " " . $application . "\n"))
私は場所の選択フィールドを作成しました.phpでは、ユーザーがフォームを送信したときにデータがファイルディレクトリに移動することを検証して確認する必要があります。
私は本当にこれにこだわっていて、すべてを試しました。どんな助けでも大歓迎です。
これは選択フィールドのコードです
<label for="location">Location:</label>
<select name="location" form="locationform">
<option value="---">---</option>
<option value="act">ACT</option>
<option value="nsw">NSW</option>
<option value="nt">NT</option>
<option value="qld">QLD</option>
<option value="sa">SA</option>
<option value="tas">TAS</option>
<option value="vic">VIC</option>
<option value="wa">WA</option>
</select>
これはphpの場所部分のコードです
<?php
//Opening, and creating a path for diretories to create
$newdir = "../../data/jobs2";
umask(0007);
$errors = array(); //sets an error array, this will append to an error string
$applicationArray = (isset($_POST['applicationby']) ? $_POST['applicationby'] : null);
if (isset($_POST["positionid"]))
{
$positionID = $_POST["positionid"];
$patternID = "/^P[0-9]{4}$/"; //This regex ensure that the first letter is start with P following number 0-9 in length of 4.
if (preg_match($patternID, $positionID)) //check if the statuscode is matches with the regex
{
$ans = "";
$length = strlen($positionID);
echo $positionID . "<br />";
}
}
else
{
array_push($errors, "Please fill in Position ID as they are mandatory field"); //To ensure and detect if there is any error
}
if (isset ($_POST["title"]))
{
$title = $_POST["title"];
$pattern = "/^[a-zA-Z\s\.,!]{0, 20}*$/"; //This regex ensure that alphanumeric character, space, comma, period, and exclamation mark, other symbols or characters are not allowed and maximum of 20 alphanumeric characters.
if (preg_match($pattern, $title)) //Check that the status if matches with the regex
{
echo $title . "<br />";
}
}
else
{
array_push($errors, "<b>Error:</b> Please fill in Status as they are mandatory field!");
}
if (isset ($_POST["description"]))
{
$description = $_POST["description"];
$patternDescription = "^[a-zA-Z0-9._ \t]{1,260}$"; //This regex ensure that the description is set to maximum character is up to 260
if (preg_match('/' . $patternDescription . '/', $description)) //Check that the description is matches with the regex
{
echo $description . "<br />";
}
}
else
{
array_push($errors, "<b>Error:</b> Please fill in Description as they are mandatory field!");
}
if (isset ($_POST["position"]))
{
$positionButton = $_POST["position"];
echo $positionButton . "<br />";
}
else
{
//Not possible unless in exceptional circumstances
array_push($errors, "Please choose the position");
}
if (isset ($_POST["contract"]))
{
$contractButton = $_POST["contract"];
echo $contractButton . "<br />";
}
else
{
//Not possible unless in exceptional circumstances
array_push($errors, "Please choose the contract");
}
if (isset($_POST['location']))
{
$location1 = $_POST['location'];
echo $location1 . "<br />";
}
else
{
array_push($errors, "please choose the location");
}
if (isset($_POST["date"]))
{
// writing the date format
$date = date("d/m/y");
echo $date . "<br />";
} else {
//$date = $_POST["date"];
}
if (isset($applicationArray))
{
//Display no "array" name, by creating a new variable name
foreach($applicationArray as $application)
{
echo $application . "<br />";
}
}
//check if file exist
if(!file_exists($newdir)){
//create a directory
mkdir($newdir, 02770);
}
$jobTxt = fopen($newdir. "/jobs2.txt", "a+");
// This is to ensure that the file is
if (is_writeable($newdir. "/jobs2.txt")) {
//write the following variable
if (fwrite($jobTxt, $positionID . " " . $title . " " . $description . " " . $positionButton . " " . $contractButton . " " . $location1 . " " . $date . " " . $application . "\n"))
{
}
echo "<p>Your form has succesfully been submit!</p>";
}
fclose($jobTxt);
if(isset($positionID, $title))
{
//Validation Check
//Check if characters length is less or more than 5 characters
if (0 === strlen($positionID > 5 || $positionID < 5))
{
array_push($errors, "<b>Error:</b> Your characters length is either less or more than 5 characters<br/>");
}
//Check if characters length is less or more than 20 characters
if (0 === strlen($title > 20))
{
array_push($errors, "<b>Error:</b> Your characters length is more than 20 characters, the maximum number is 20 alphanumeric characters!<br/>");
}
//Check if Position ID is left not blank
if (0 === preg_match("/\S+/", $positionID))
{
array_push($errors, "<b>Error:</b> You forgot to fill in the Position ID!<br />");
}
//Check if Title is left not blank
if (0 === preg_match("/\S+/", $title))
{
array_push($errors, "<b>Error:</b> You forgot to fill in the Title! <br />");
}
//Check if user made a mistake with typo
if (0 === preg_match($patternID, $positionID))
{
array_push($errors, "<b>Error:</b> please make sure that the first letter in Status Code is uppercase 'P' following by 4 numbers. <br />");
}
//Remind user to avoid the unnecessary symbol
if (0 === preg_match($pattern, $title))
{
array_push($errors, "<b>Error:</b> Please make sure to avoid symbols other than \",.!\" <br />");
}
}
if (isset($errors))
{
//Display no array name by changing the variable
foreach ($errors as $error)
{
echo '<strong>', $error, '</strong>';
}
}
//provide back to form page link
echo '<a href="jobpostform.php">Back to Form page.</a> <br />';
//provide back to home page link
echo '<a href="index.php">Back to Home page.</a>';
?>