Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP-无法通过get和post从文本框中获取文本_Php_Get - Fatal编程技术网

PHP-无法通过get和post从文本框中获取文本

PHP-无法通过get和post从文本框中获取文本,php,get,Php,Get,我有3个文本框,但我无法使用$\u get和$\u POST选项获取它的值。我需要这样的东西: -我用文本填充文本框 -我点击按钮 -我在点击按钮时激活该功能 -在这个函数中,我从文本框接收文本 -我保存到文件保存到文件作品 <!doctype html> <html> <head> <meta charset="utf-8"> <title>One Hit Point</title> <link href="Bez_

我有3个文本框,但我无法使用$\u get和$\u POST选项获取它的值。我需要这样的东西: -我用文本填充文本框 -我点击按钮 -我在点击按钮时激活该功能 -在这个函数中,我从文本框接收文本 -我保存到文件保存到文件作品

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>One Hit Point</title>
<link href="Bez_nazwy1.css" rel="stylesheet">
<link href="test.css" rel="stylesheet">
</head>
<body>
<form action="<?php $_PHP_SELF ?>" method="GET">
<label for="" id="Label1" style="position:absolute;left:67px;top:16px;width:194px;height:31px;line-height:31px;z-index:0;">Imię</label>
<input type="text" id="x11" name="x1" style="position:absolute;left:158px;top:23px;width:196px;height:16px;z-index:1;" value="">
<label for="" id="Label2" style="position:absolute;left:67px;top:63px;width:289px;height:31px;line-height:31px;z-index:2;">Nazwisko</label>
<input type="text" id="x22" name="x2" style="position:absolute;left:158px;top:70px;width:196px;height:16px;z-index:3;" value="">

<label for="" id="Label3" style="position:absolute;left:67px;top:111px;width:194px;height:31px;line-height:31px;z-index:5;">Telefon</label>
<input type="text" id="x33" name="x3" style="position:absolute;left:158px;top:118px;width:196px;height:16px;z-index:6;" value="+48 ">
<input type="button" id="Button1" onclick="<?php costam() ?>;" name="" value="Zatwierdź" style="position:absolute;left:194px;top:164px;width:96px;height:25px;z-index:7;">
</form>
</body>

<body>
<?php
//window.location.href='./niespodzianka.html';return false;
function costam(){
    $imie= $_GET['x1'];
    $Nazwisko=$_GET['x2'];
    $Numer= $_GET['x3'];
    //łączenie
    $dane=$imie.", ".$Nazwisko.", ".$Numer;
    //dodawanie nowej linii
    $popr=$dane." k\n";
    //otwieranie, zapisanie, zamknięcie
    $plik=fopen("zap.txt", "a");
    fputs($plik, $popr);
    fclose($plik);
}
?>
</body>
</html>
编辑:

新代码现在有2个文件: 文件1 dz.php:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>One Hit Point</title>
<link href="Bez_nazwy1.css" rel="stylesheet">
<link href="test.css" rel="stylesheet">
</head>
<body>
<form action="pliki.php" method="GET">
<label for="" id="Label1" style="position:absolute;left:67px;top:16px;width:194px;height:31px;line-height:31px;z-index:0;">Imię</label>
<input type="text" id="x11" name="x1" style="position:absolute;left:158px;top:23px;width:196px;height:16px;z-index:1;" value="">
<label for="" id="Label2" style="position:absolute;left:67px;top:63px;width:289px;height:31px;line-height:31px;z-index:2;">Nazwisko</label>
<input type="text" id="x22" name="x2" style="position:absolute;left:158px;top:70px;width:196px;height:16px;z-index:3;" value="">
<label for="" id="Label3" style="position:absolute;left:67px;top:111px;width:194px;height:31px;line-height:31px;z-index:5;">Telefon</label>
<input type="text" id="x33" name="x3" style="position:absolute;left:158px;top:118px;width:196px;height:16px;z-index:6;" value="+48 ">
<input type="button" id="Button1" onclick="location.href='pliki.php'" name="" value="Zatwierdź" style="position:absolute;left:194px;top:164px;width:96px;height:25px;z-index:7;">
</form>
</body>
</html>
文件2 pliki.php:

<?php
//window.location.href='./niespodzianka.html';return false;

$imie= $_GET['x1'];
$Nazwisko=$_GET['x2'];
$Numer= $_GET['x3'];
//łączenie
$dane=$imie.", ".$Nazwisko.", ".$Numer;
//dodawanie nowej linii
$popr=$dane." k\n";
//otwieranie, zapisanie, zamknięcie
$plik=fopen("zap.txt", "a");
fputs($plik, $popr);
fclose($plik);
?>

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Bez nazwy</title>
<meta name="generator" content="WYSIWYG Web Builder 14 - http://www.wysiwygwebbuilder.com">
<link href="Bez_nazwy1.css" rel="stylesheet">
<link href="niespodzianka.css" rel="stylesheet">
</head>
<body>
<div id="wb_TextArt1" style="position:absolute;left:16px;top:13px;width:867px;height:470px;z-index:0;">
<img src="images/img0001.png" id="TextArt1" alt="Bede dzowni&#263; xd" title="Bede dzowni&#263; xd" style="width:867px;height:470px;"></div>
</body>
</html>

那代码不起作用。不能使用javascript onclick调用PHP函数。 为了您的澄清,此代码将在每次加载页面时执行costam函数

尝试使用以下命令更改按钮1:

这应该是可行的,但不是一个好方法。页面也将刷新

如果您熟悉jQuery:


这可能会帮助您:

您不能从onclick调用PHP函数。什么都不做,如果使用可能会让你接受xss注射。你需要去彻底阅读,我能做什么?如何调用我的函数?我已经更改了答案,希望这能对您有所帮助。编辑了主要答案,您能检查一下吗?是的,请看我答案的第一部分。删除onclick并使用如下输入:Finnaly,在6小时后工作:P非常感谢!
<input type="submit" id="Button1" name="submit" value="Zatwierdź" style="position:absolute;left:194px;top:164px;width:96px;height:25px;z-index:7;">
<?php
if($_GET['submit']){
    $imie= $_GET['x1'];
    $Nazwisko=$_GET['x2'];
    $Numer= $_GET['x3'];
    //łączenie
    $dane=$imie.", ".$Nazwisko.", ".$Numer;
    //dodawanie nowej linii
    $popr=$dane." k\n";
    //otwieranie, zapisanie, zamknięcie
    $plik=fopen("zap.txt", "a");
    fputs($plik, $popr);
    fclose($plik);
}
jQuery.ajax({
type: "POST",
url: 'your_functions_address.php',
dataType: 'json',
data: {functionname: 'add', arguments: [1, 2]},

success: function (obj, textstatus) {
              if( !('error' in obj) ) {
                  yourVariable = obj.result;
              }
              else {
                  console.log(obj.error);
              }
        }
});