Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.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变量输出存储到PHP变量和数据库中?_Javascript_Php_Jquery_Mysql - Fatal编程技术网

将JavaScript变量输出存储到PHP变量和数据库中?

将JavaScript变量输出存储到PHP变量和数据库中?,javascript,php,jquery,mysql,Javascript,Php,Jquery,Mysql,我能够将javascript变量输出到php变量中,但我无法将从javascript变量存储的php变量值存储到数据库中,因为它存储了整个脚本,例如: <script>document.write(answer)</script> document.write(回答) 我尝试在注册页面上重定向更新,但它在同一页面上保持静态 这是我的密码: if(isset($_GET['status'])) { if($_GET['status']=="Rejected") { e

我能够将javascript变量输出到php变量中,但我无法将从javascript变量存储的php变量值存储到数据库中,因为它存储了整个脚本,例如:

<script>document.write(answer)</script>
document.write(回答)
我尝试在注册页面上重定向更新,但它在同一页面上保持静态

这是我的密码:

if(isset($_GET['status'])) 
{
if($_GET['status']=="Rejected")
{
echo("<script type='text/javascript'> var answer = prompt('Please enter'); </script>");?>
<script>var a = document.write(answer);
window.location.href = window.location.href+'#reason='+answer;</script>
<?php
if(isset($_GET['reason']))
{
$reason=$_GET['reason'];
$approve="UPDATE approveleave SET status='Rejected',rejectreason='".$reason."' WHERE id='".$id."'";
$result2=mysql_query($approve,$con);
header("location:registration.php");
}
}
}   
?>
if(isset($\u GET['status']))
{
如果($_GET['status']==“已拒绝”)
{
echo(“var answer=prompt('Please enter');”);?>
var a=文件写入(回答);
window.location.href=window.location.href+'#reason='+答案;

要通过url传递数据,应使用“?”字符

你的剧本

 window.location.href = window.location.href+'#reason='+answer;</script>
window.location.href=window.location.href+'#reason='+答案;
应该怎样

window.location.href = window.location.href+'?reason='+answer;</script>
window.location.href=window.location.href+'?原因='+答案;
重新格式化代码:

if(!empty($_GET['status']) && $_GET['status'] == "Rejected") {
        if(!empty($_GET['reason'])) {
            $reason = $_GET['reason'];
            $approve="UPDATE approveleave SET status='Rejected',rejectreason='".$reason."' WHERE id='".$id."'";
            $result2=mysql_query($approve,$con);
            header("location: /registration.php");
        } else {
          ?>
          <script type='text/javascript'> 
            var answer = prompt('Please enter'); 
            var a = document.write(answer);
            window.location.href = window.location.href+'?reason='+answer;
          </script>
          <?php
        }
}
if(!empty($\u GET['status'])&&&$\u GET['status']==“拒绝”){
如果(!empty($\u GET['reason'])){
$reason=$_GET['reason'];
$approve=“UPDATE approveleave SET status='Rejected',rejectreason='”$reason.”其中id='“$id.”;
$result2=mysql\u查询($approve,$con);
标题(“location:/registration.php”);
}否则{
?>
var answer=提示(“请输入”);
var a=文件写入(回答);
window.location.href=window.location.href+'?原因='+答案;

var answer=提示(“请输入”);
var a=文件写入(回答);
window.location.href=window.location.href+'&reason='+answer;

您的代码可能是这样的

<?php 
if(isset($_GET['status'])) 
{
     if($_GET['status']=="Rejected")
    {

            echo("<script type='text/javascript'> var answer = prompt('Please enter'); </script>");?>
        <script>var a = document.write(answer);
        window.location.href = window.location.href+'&reason='+answer;</script>

<?php if(isset($_GET['reason'])) {
                      $reason=$_GET['reason'];
                        $approve="UPDATE approveleave SET status='Rejected',rejectreason='".$reason."' WHERE id='".$id."'";
                        $result2=mysql_query($approve,$con);
                      header("location:registration.php");
                  }


    }
}   
?>

您在php中错误地编写了js此代码乱七八糟。请阅读我尝试使用的“?”字符仍然得到相同的结果。我将永远重新格式化您的代码,但您需要确保javascript将在您的浏览器中无错误地运行,并确保如果状态为OK是的,我将确保它得到运行我刚刚在@Neo Morina处做了几处更改它工作了唯一的问题是在重定向之前它显示了没有e的值cho.你试过上面的代码吗?我感觉你的问题是mysql连接。使用你的代码仍然无法重定向并插入到数据库中。你能给出你正在使用查询参数尝试的URL吗?你是否得到正确的数据插入到数据库中?此代码给出了未定义错误,原因是我刚刚更新了code、 你能检查一下吗?
<?php 
if(isset($_GET['status'])) 
{
     if($_GET['status']=="Rejected")
    {

            echo("<script type='text/javascript'> var answer = prompt('Please enter'); </script>");?>
        <script>var a = document.write(answer);
        window.location.href = window.location.href+'&reason='+answer;</script>

<?php if(isset($_GET['reason'])) {
                      $reason=$_GET['reason'];
                        $approve="UPDATE approveleave SET status='Rejected',rejectreason='".$reason."' WHERE id='".$id."'";
                        $result2=mysql_query($approve,$con);
                      header("location:registration.php");
                  }


    }
}   
?>