PROBLEMA Php e mysql

MrAxsus

Nuovo Utente
144
7
CPU
Intel® Core™ i5-4690
Dissipatore
Hyper 212 EVO
Scheda Madre
Gigabyte GA-H97-HD3
HDD
Western Digital Caviar Blue 1TB SanDisk Plus 120Gb
RAM
Kingston HyperX Beast - 8GB
GPU
Sapphire Nitro r9 380 4G OC
Audio
Creative Sound Blaster Z
Monitor
Asus VE247H
PSU
XFX TS Series 550W
Case
Carbide Series® SPEC-03 Red LED Windowed
OS
Windows 10 Pro (64bit)
Salve sto creando un area riservata con php, però mi da i seguenti errori:
Il codice è il sequente:
Codice:
<?php
include("dbconfig.php");
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST")
{
// username and password received from loginform
$username=mysqli_real_escape_string($dbconfig,$_POST['username']);
$password=mysqli_real_escape_string($dbconfig,$_POST['password']);

$sql_query="SELECT id FROM user WHERE username='$username' and password='$password'";
$result=mysqli_query($dbconfig,$sql_query);
$row=mysqli_fetch_array($result,MYSQLI_ASSOC);
$count=mysqli_num_rows($result);


// If result matched $username and $password, table row must be 1 row
if($count==1)
{
$_SESSION['login_user']=$username;

header("location: areariservata.html");
}
else
{
$error="Username e Password non sono validi.";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<link href='http://fonts.googleapis.com/css?family=Montserrat:400,700' rel='stylesheet' type='text/css'>
<meta charset="UTF-8">
<title>Area Riservata</title>
<style>
body {
    background-size: cover;
    font-family: Montserrat;
}

.logo {
    width: 213px;
    height: 36px;
    margin: 30px auto;
}

.login-block {
    width: 320px;
    padding: 20px;
    background: #fff;
    border-radius: 5px;
    border-top: 5px solid #ff656c;
    margin: 0 auto;
}

.login-block h1 {
    text-align: center;
    color: #000;
    font-size: 18px;
    text-transform: uppercase;
    margin-top: 0;
    margin-bottom: 20px;
}

.login-block input {
    width: 100%;
    height: 42px;
    box-sizing: border-box;
    border-radius: 5px;
    border: 1px solid #ccc;
    margin-bottom: 20px;
    font-size: 14px;
    font-family: Montserrat;
    padding: 0 20px 0 50px;
    outline: none;
}

.login-block input#username {
    background: #fff url('http://i.imgur.com/u0XmBmv.png') 20px top no-repeat;
    background-size: 16px 80px;
}

.login-block input#username:focus {
    background: #fff url('http://i.imgur.com/u0XmBmv.png') 20px bottom no-repeat;
    background-size: 16px 80px;
}

.login-block input#password {
    background: #fff url('http://i.imgur.com/Qf83FTt.png') 20px top no-repeat;
    background-size: 16px 80px;
}

.login-block input#password:focus {
    background: #fff url('http://i.imgur.com/Qf83FTt.png') 20px bottom no-repeat;
    background-size: 16px 80px;
}

.login-block input:active, .login-block input:focus {
    border: 1px solid #ff656c;
}

.login-block button {
    width: 100%;
    height: 40px;
    background: #ff656c;
    box-sizing: border-box;
    border-radius: 5px;
    border: 1px solid #e15960;
    color: #fff;
    font-weight: bold;
    text-transform: uppercase;
    font-size: 14px;
    font-family: Montserrat;
    outline: none;
    cursor: pointer;
}

.login-block button:hover {
    background: #ff7b81;
}

</style>
</head>

<body>

<div class="logo"></div>
<div class="login-block">
    <h1>Area Riservata</h1>
    <form method="post" action="" name="loginform">
    <input type="text" value="" placeholder="Username" id="username" name="username" />
    <input type="password" value="" placeholder="Password" id="password" name="password" />
    <button type="submit">Entra</button>
    </form>
</div>
</body>

</html>
 

MrAxsus

Nuovo Utente
144
7
CPU
Intel® Core™ i5-4690
Dissipatore
Hyper 212 EVO
Scheda Madre
Gigabyte GA-H97-HD3
HDD
Western Digital Caviar Blue 1TB SanDisk Plus 120Gb
RAM
Kingston HyperX Beast - 8GB
GPU
Sapphire Nitro r9 380 4G OC
Audio
Creative Sound Blaster Z
Monitor
Asus VE247H
PSU
XFX TS Series 550W
Case
Carbide Series® SPEC-03 Red LED Windowed
OS
Windows 10 Pro (64bit)
Gli errori:

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /storage/ssd1/120/2267120/public_html/login.php on line 12

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /storage/ssd1/120/2267120/public_html/login.php on line 13
 

cdtux

Utente Èlite
1,829
911
CPU
I7 3770
Scheda Madre
Asrock Z77 Extreme 4
HDD
Samsung 850 pro 250GB
RAM
Corsair Vengeance LP 16GB
GPU
Gigabyte GTX1060 6GB
Monitor
Dell U2412M
PSU
Seasonic Focus Plus 650
Case
Corsair Graphite 760T
OS
Debian / Ubuntu
Spero che il codice sia solo per studio e non implementato in un sito online.

Probabilmente la query ritorna un bel FALSE, per questo hai quegli errori.

Per vedere l'errore da cosa è provocato sostiruisci questa riga:
PHP:
$result=mysqli_query($dbconfig,$sql_query);

con:
PHP:
$result=mysqli_query($dbconfig,$sql_query) or die ("ERRORE: " . mysqli_error($dbconfig));
 

MrAxsus

Nuovo Utente
144
7
CPU
Intel® Core™ i5-4690
Dissipatore
Hyper 212 EVO
Scheda Madre
Gigabyte GA-H97-HD3
HDD
Western Digital Caviar Blue 1TB SanDisk Plus 120Gb
RAM
Kingston HyperX Beast - 8GB
GPU
Sapphire Nitro r9 380 4G OC
Audio
Creative Sound Blaster Z
Monitor
Asus VE247H
PSU
XFX TS Series 550W
Case
Carbide Series® SPEC-03 Red LED Windowed
OS
Windows 10 Pro (64bit)
Grazie per il tuo aiuto, vorrei sapere perchè non posso inserirlo su un sito online?
 

cdtux

Utente Èlite
1,829
911
CPU
I7 3770
Scheda Madre
Asrock Z77 Extreme 4
HDD
Samsung 850 pro 250GB
RAM
Corsair Vengeance LP 16GB
GPU
Gigabyte GTX1060 6GB
Monitor
Dell U2412M
PSU
Seasonic Focus Plus 650
Case
Corsair Graphite 760T
OS
Debian / Ubuntu
Oltre alle password in chiaro (cosa gravissima) non hai nel form token per prevenire i csrf attack.
 
  • Mi piace
Reazioni: Mursey

MrAxsus

Nuovo Utente
144
7
CPU
Intel® Core™ i5-4690
Dissipatore
Hyper 212 EVO
Scheda Madre
Gigabyte GA-H97-HD3
HDD
Western Digital Caviar Blue 1TB SanDisk Plus 120Gb
RAM
Kingston HyperX Beast - 8GB
GPU
Sapphire Nitro r9 380 4G OC
Audio
Creative Sound Blaster Z
Monitor
Asus VE247H
PSU
XFX TS Series 550W
Case
Carbide Series® SPEC-03 Red LED Windowed
OS
Windows 10 Pro (64bit)
e come faccio a prevenire?
 
D

deleted_97382

Ospite
Ti consiglierei di utilizzare soluzioni che ti mettano a disposizione già api e feature per sviluppare in modo strutturato, come Laravel o Symphony
 

Entra

oppure Accedi utilizzando
Discord Ufficiale Entra ora!

Discussioni Simili