显示变量的内容是不工作有我的PHP代码
这里的问题是我的PHP代码的$schanName
if($_POST['thisfolder'] == 'default') {
$schanName = 'Please select a Name';
return;
}
变量名我已经试过这呼应了在以往任何时候我想
字符串<div id="err" style="color:#fff;"><?php echo $schanName ?></div>
但它没有显示任何内容。
,如果我尝试这样它会工作
if($_POST['thisfolder'] == 'default') {
echo 'Please select a Name';
return;
}
,但我不知道我做错了那里,它不工作。
编辑#2这里我的整个页面
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<div id="error"> i must display that error here</div>
<form class="s_submit" method="post">
<label class="def_lab">File:</label>
<input class="t_box" type='text' name='filename' placeholder='File Name'>
<label class="t_lab def_lab">Select Folder:</label>
<select id="soflow" name="thisfolder">
<option selected="selected" value="default">Default</option>
<option value="../embed/tv/xbox/">Xbox</option>
<option value="Folder2">Folder2</option>
<option value="Folder3">Folder3</option>
</select><br><br>
<label class="def_lab">Text Area 1:</label><br>
<textarea class="tarea_box" type='text' name='strin'></textarea><br><br>
<label class="def_lab">Text Area 2:</label><br>
<textarea class="tarea_box" type='text' name='strin2'></textarea><br>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
<?php
var_dump($_POST);
$fNum = 'File Name is Required';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if(empty($_POST['filename'])) {
echo $fNum;
return;
}
if($_POST['thisfolder'] == 'default') {
$schanName = 'Please select a Folder';
return;
}
$filename=$_POST['filename'];
$words = array("1", "2", "3", "4", "5");
$arrlength = count($words);
$found = false;
for($x = 0; $x < $arrlength; $x++) {
if($filename == $words[$x])
{
$found = true;
}
}
if($found)
{
echo 'Not a valid File Name';
return;
}
// the name of the file to create
$filename=$_POST['filename'];
// the name of the file to be in page created
$strin=$_POST['strin'];
// the name of the file to be in page created
$strin2=$_POST['strin2'];
// the name of the folder to put $filename in
$thisFolder = $_POST['thisfolder'];
// make sure #thisFolder of actually a folder
if (!is_dir(__DIR__.'/'.$thisFolder)) {
// if not, we need to make a new folder
mkdir(__DIR__.'/'.$thisFolder);
}
// . . . /[folder name]/page[file name].php
$myFile = __DIR__.'/'.$thisFolder. "/page" .$filename.".php";
// This is another way of writing an if statment
$div = ($strin !== '') ? '<div id="area_code">'.$strin.'</div>' : '<div id="area_code">'.$strin2.'</div>';
$fh = fopen($myFile, 'w');
$stringData = "";
fwrite($fh, $stringData);
fclose($fh);
}
?>
</body>
</html>
当用户什么都不输入时,您不处理这种情况。您只能在用户输入“默认”时处理 – Psi
您为什么使用“返回”? – user3526204
这是在一个函数或东西? 'return'怎么回事? –