일반인이 요청했기 때문에! 이것은 내 대답을 전체 대답으로 확장 한 것입니다 :
$_GET
과 $_POST
을 모두 사용하고 있습니다. 이것은 일반적이지 않습니다. 의도적으로이 작업을 수행하고 있습니까? 내 추측은 : 아니오. 당신이 당신의 HTML에서 볼 경우
당신은이 :
<form name="recAdd" method="GET" action="add.php">
이는 GET
될 것입니다 브라우저에서 요청을 의미합니다. 당신은 POST로 변경할 수 있습니다 중 하나
<form name="recAdd" method="POST" action="add.php">
PHP (은 add.php) :
switch($_POST['rec']){
case '1':
$rec1 = "rec1.txt";
$fh = fopen($rec1, 'a') or die("can't open file");
$romString = $_POST['name']; //<---
fwrite($fh, $romString);
fclose($fh);
print 'something'; //<<--- fixed syntax, btw: I would use echo
break;
case '2':
// do Something
break;
case '3':
// do Something
break;
default:
print("Not working ;(");
}
참고 :이 변화에 테스트 한 노력하고 있습니다.
아니면 모든 GET로 변경
switch($_GET['rec']){ //<-----
case '1':
$rec1 = "rec1.txt";
$fh = fopen($rec1, 'a') or die("can't open file");
$romString = $_GET['name'];
fwrite($fh, $romString);
fclose($fh);
print 'something'; //<<--- fixed syntax, btw: I would use echo
break;
case '2':
// do Something
break;
case '3':
// do Something
break;
default:
print("Not working ;(");
}
웹 서버 (즉, 아파치) 대상 폴더에 쓸 수있는 권한이 있는지 확인합니다 (I는 POST로 유지하는 것이 좋습니다). 이로 인해 작업이 성공하지 못할 수 있습니다.
PHP의 오류 메시지를 켜면 상황에 대한 통찰력을 얻을 수 있습니다. 당신이 가진 현재의 PHP 스크립트를 수행 할 수 있습니다
error_reporting(E_ALL | E_STRICT);
참고 : error_reporting at php.net
당신은 당신과 같이 $_SERVER['REQUEST_METHOD']
을 시도 할 수 있습니다 사용 된 것을 요청 방법이 확실하지 않은 경우 :
if ($_SERVER['REQUEST_METHOD'] === 'POST')
{
//Ok we got a POST, probably from a FORM, read from $_POST.
var_dump($_PSOT); //Use this to see what info we got!
}
else
{
//You could assume you got a GET
var_dump($_GET); //Use this to see what info we got!
}
참고 : $_SERVER at php.net
또한 PHP Session management 및 Post-Redirect-Get에 관심이 있으실 것입니다.그것으로 당신이 할 수 있습니다 :
if ($_SERVER['REQUEST_METHOD'] === 'POST')
{
//Ok we got a POST, probably from a FORM, read from $_POST.
var_dump($_PSOT); //Use this to see what info we got!
//Do stuff...
//Write results to session
session_start();
$_SESSION['stuff'] = $something;
//redirect:
header('Location: add.php', true, 303);
//The redirection will cause the browser to request with GET
//The results of the operation are in the session variable
exit();
}
else
{
//You could assume you got a GET
var_dump($_GET); //Use this to see what info we got!
//Get stuff from session
session_start();
if (array_key_exists('stuff', $_SESSION))
{
$something = $_SESSION['stuff'];
//we got stuff
//later use present the results of the operation to the user.
}
//clear stuff from session:
unset($_SESSION['stuff']);
}
참고 : 귀하의 양식은 add.php 할 데이터를 전송하기 위해 get 메소드를 사용 $_SESSION at php.net
Stackoverflow를 사용하면 123이 표시됩니다. - Theraot를 편집 해 주셔서 감사합니다. – user1043816
GET 및 POST를 용도에 맞게 혼합하고 있습니까? 그리고 ... 너의 질문은 또 뭐야? 어떤 요청 방법이 사용되었는지 확실하지 않으면 $ _SERVER [ 'REQUEST_METHOD']를 시도해보십시오. – Theraot
@Theraot 답변으로 게시해야합니다. –