I'm trying to get everything from an table whit php/mysql but it won't work. I tried to search but i don't know what is making the error. I hope you can help me.
this the code:
$servername = "localhost"; //Location Of Database - usually it's "localhost"
$username = "root"; //Database User Name
$password = ""; //Database Password
$dbname = "hr"; //Database Name
$naam = mysql_real_escape_string($_POST['filler']);
$naam2 = mysql_real_escape_string($_POST['name']);
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql="SELECT * FROM antwoorden WHERE 'filler'='$naam' AND
'name'='$naam2'";
if ($conn->query($sql) === TRUE) {
$row = $result->fetch_row();
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$date = $row[2];
$C_KVW = $row[5];
$TL_KVW = $row[6];
$C_AW = $row[7];
$TL_AW = $row[8];
$C_FB = $row[9];
$TL_FB = $row[10];
$C_FO = $row[11];
$TL_FO = $row[12];
$C_SW = $row[13];
$TL_SW = $row[14];
$C_WC = $row[15];
$TL_WC = $row[16];
$C_ST = $row[17];
$TL_ST = $row[18];
$C_CF = $row[19];
$TL_CF = $row[20];
$C_OP = $row[21];
$TL_OP = $row[22];
$C_IN = $row[23];
$TL_IN = $row[24];
$C_NA = $row[25];
$TL_NA = $row[26];
$C_OB = $row[27];
$TL_OB = $row[28];
$gemcijf = $row[29];
echo("De antwoorden zijn: <br/>".$date." & ".$C_KVW." & ".$TL_KVW." & ".$C_AW." & ".$TL_AW." & ".$C_FB." & ".$TL_FB." & ".$C_FO." & ".$TL_FO." & ".$C_SW." & ".$TL_SW." & ".$C_WC." & ".$TL_WC." & ".$C_ST." & ".$TL_ST." & ".$C_CF." & ".$TL_CF." & ".$C_OP." & ".$TL_OP." & ".$C_IN." & ".$TL_IN." & ".$C_NA." & ".$TL_NA." & ".$C_OB." & ".$TL_OB." & ".$gemcijf );
and the error i get:
Error: SELECT * FROM antwoorden WHERE 'filler'='bart' AND 'name'='willem'
De antwoorden zijn:
& & & & & & & & & & & & & & & & & & & & & & & & &
No need of
'
s around the column names -filter
orname
. You may use backticks instead -UPDATE
There is no more errors in the query. You are doing -
Which checks for identical
true
with the return value of$conn->query($sql)
which will be always false as it will return theresource
object nottrue
for successfullSELECT
. You should do it like -instead.
$conn->query($sql)
will returnfalse
if there is any error regarding database or query.