Когда очень нужно JSON ответ в PHP 🙃
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
$jsonString = "ok;"; $jsonString .= "["; while ($dados = $sql1->fetch_array()) { $jsonString .= "{"; $jsonString .= "\"id\":\""; $jsonString .= $dados['id']; $jsonString .= "\","; $jsonString .= "\"cpf\":\""; $jsonString .= $dados['cpf']; $jsonString .= "\","; $jsonString .= "\"nome\":\""; $jsonString .= $dados['nome']; $jsonString .= "\","; $jsonString .= "\"tipo\":\""; $jsonString .= $dados['tipo']; $jsonString .= "\""; $jsonString .= "},"; } $jsonString = rtrim($jsonString, ','); $jsonString .= "]"; echo $jsonString; |
Пример авторизации на PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
if (isset($_POST['doc-login'])){ $user_name =$_POST['username']; $password=$_POST['password']; $query="SELECT * FROM doc_logindb WHERE username='$user_name' AND password='$password'"; $result=mysqli_query($con,$query); if (mysqli_num_rows($result)==1){ $_SESSION['username']=$user_name; header("Location:docsPanel.php"); }else{ header("Location:error.php"); } } |