Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.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
Javascript 将post数据传递给php函数_Javascript_Php_Html - Fatal编程技术网

Javascript 将post数据传递给php函数

Javascript 将post数据传递给php函数,javascript,php,html,Javascript,Php,Html,我是这个网站和编程新手 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Login page</title> <script> //This is the client side form validation with Javascript //This code is executed on the client's b

我是这个网站和编程新手

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Login page</title>

<script> //This is the client side form validation with Javascript
//This code is executed on the client's browser
function validateForm()
{
    var x=document.getElementById("username").value;
    if (x==null || x=="") //check that the name field is not blank
    {
        alert("Your username must be filled out");
        return false;
    }
    var y =document.getElementById("password").value;
    if (y==null || y=="") //check that the project field is not blank
    {
        alert("Your password must be filled out");
        return false;
    }
 }
</script>

<?php //This is the server side form validation with PHP
//This code executes on the web server
//Write your server side form validation code here
//checks form is submitted

登录页面
//这是使用Javascript进行的客户端表单验证
//此代码在客户端浏览器上执行
函数validateForm()
{
var x=document.getElementById(“用户名”).value;
如果(x==null | | x==“”)//请检查名称字段是否为空
{
提醒(“必须填写您的用户名”);
返回false;
}
var y=document.getElementById(“密码”).value;
如果(y==null | | y==“”)//请检查项目字段是否为空
{
警告(“必须填写您的密码”);
返回false;
}
}

你想退回$uname吗

function checkUserData($inputData) {
    return stripslashes(trim(htmlspecialchars($inputData)));
}
echo checkUserData($_POST['uname']);

我不太明白你想用php做什么。让我知道这是否解决了您的问题,我将详细说明我的答案。

您是否试图退还$uname

function checkUserData($inputData) {
    return stripslashes(trim(htmlspecialchars($inputData)));
}
echo checkUserData($_POST['uname']);

我不太明白你想用php做什么。让我知道这是否解决了您的问题,我将详细说明我的答案。

我不知道您的帖子中是否遗漏了一些内容,或者您忘记了添加整个代码。但是您根本没有得到任何post变量。因此,为了获得数据并进行验证,您需要这样做

$username = $_POST['uname'];
checkUserData($username);

从你的帖子中还不能百分之百地清楚你想做什么

我不知道你的帖子中是否遗漏了什么,或者你忘记了添加整个代码。但是您根本没有得到任何post变量。因此,为了获得数据并进行验证,您需要这样做

$username = $_POST['uname'];
checkUserData($username);

从你的帖子中还没有100%清楚你想做什么

我想你确实使用了服务器变量$\u post

例如:

<?php
   //Check if request is POST
   if($_SERVER['REQUEST_METHOD'] == 'POST'){
      $username = checkUserData($_POST['uname']);
      $password = checkUserData($_POST['pwd']);
   }

   function checkUserData($inputData) {
      $inputData = htmlspecialchars($inputData);
      $inputData = trim($inputData);
      $inputData = stripslashes($inputData); 
      return $inputData;
   }
?>


希望这对您有所帮助

我想您确实使用了服务器变量$\u POST

例如:

<?php
   //Check if request is POST
   if($_SERVER['REQUEST_METHOD'] == 'POST'){
      $username = checkUserData($_POST['uname']);
      $password = checkUserData($_POST['pwd']);
   }

   function checkUserData($inputData) {
      $inputData = htmlspecialchars($inputData);
      $inputData = trim($inputData);
      $inputData = stripslashes($inputData); 
      return $inputData;
   }
?>


希望这有助于检查所有已发布表单字段,您可以使用:

foreach($_POST as $key => $val)
{
  checkUserData($val);
}

要检查所有已过账表单字段,您可以使用:

foreach($_POST as $key => $val)
{
  checkUserData($val);
}

函数checkUserData(){$username=$\u POST['username'];}你是这样的意思吗?函数checkUserData(){$username=$\u POST['username'];}你是这样的意思吗?如果使用mysql,不要忘记转义字符串。如果使用mysql,不要忘记转义字符串