【问题标题】:Does php code not run?No error messagephp代码没有运行吗?没有错误信息
【发布时间】:2017-10-30 15:16:27
【问题描述】:

我尝试了这个 php 代码(我已经阅读了关于 sql Injection 的内容)但显然它没有运行,没有错误消息或其他任何东西......

<?php
function SignIn(){
  session_start();
  require_once("dbConnection.php");
  if(isset($_POST['submit'])){
       $db_handle = new DBConnection();
     $username = $_POST["username"];
     if(filter_var($username, FILTER_VALIDATE_EMAIL)===true && strpos(explode('@',$username),"studio.unibo.it")===true){
         $query =  $db_con->prepare("SELECT * FROM studenti_in_sessione
         WHERE Username=:username");
         $query->execute(array(":username"=>$username));
         $row = $query->fetch(PDO::FETCH_ASSOC);
         $count = $query->rowCount();
         if($row['Username']==$username){
            echo "<script language = javascript>
                alert(\"Autenticazione riuscita,Le invieremo nella mail istituzionale un codice univoco di autenticazione.\");
                window.history.go(-1);
            </script>";
            $querySession = $db_con->prepare("SELECT Nome, Cognome, Matricola FROM studenti_in_sessione
       WHERE Username:=username");
       $querySession->execute(array(":username"=>$username));
       $rowStud = $querySession->fetch(PDO::FETCH_ASSOC);
       $exit = array_values($rowStud);
       $queryInsert = $db_con->prepare("INSERT INTO studente (Nome, Cognome, Matricola, Username, Codice) VALUES('".$exit[0]."',
          '".$exit[1]."','".$exit[2]."','".$username."');");
       $resultInsert = $queryInsert->execute();
       sendCode($username);
     }
      }}else{
          echo "<script language = javascript>
                alert(\"L'indirizzo deve essere @studio.unibo.it.\");
                window.history.go(-1);
                </script>";
  }
  if(isset($_POST['submit'])){
        SignIn();
  }

?>

这是html表单

<div class="box-header">
                <h2>Login</h2>
            </div>
            <form name="form" class="form"  method="POST">
            <label for="username">Username</label>
            <br/>
            <input type="text" id="username" name="username">
            <input name="submit" id="submit" type="submit" value="Login">
        </div>

最后是 script.js

$('document').ready(function()
{ 
     /* validation */
  $(".form").validate({
      rules:
   {
   user_email: {
            required: true,
            email: true
            },
    },
       messages:
    {
            user_email: "please enter your email address",
       },
    submitHandler: submitForm 
       });  
    /* validation */

    /* login submit */
    function submitForm()
    {  
   var data = $(".form").serialize();

   $.ajax({

   type : 'POST',
   url  : '../Slide_upload/database/signIn.php',
   data : data,
   success :  function(response){      
     if(response=="ok"){

     }
     else{

     }
     }
   });
    return false;
  }
    /* login submit */
});

我可能犯了错误,但我不知道在哪里......

【问题讨论】:

  • 您需要自己调试。在每一行添加 echo 并验证
  • &lt;?php 之后在signIn.php 中添加error_reporting(E_ALL);ini_set('display_errors',1);session_start(); 并删除函数内部的session_start();。现在提交表单并检查您的浏览器控制台是否有错误或成功
  • 如果代码根本没有运行,页面是空白的,原因通常是语法错误。
  • 您正在使用strpos 的返回值并检查它是否为真(使用===),尝试使用!== false,因为strpos 将返回一个数字位置,如果它找到字符串而不是是的。
  • 很遗憾,这些解决方案都不起作用

标签: javascript php html mysql pdo


【解决方案1】:

当然,您缺少一个括号来关闭未执行的函数。 在行前添加它

if(isset($_POST['submit'])){
    SignIn();

}

这将使您的函数调用正常工作。

【讨论】:

    猜你喜欢
    • 2013-07-25
    • 1970-01-01
    • 1970-01-01
    • 2017-10-19
    • 1970-01-01
    • 2019-06-17
    • 2017-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多