this is some of my PHP and SQL to add a variable, $d, to an existing value in my mySQL table.
if ($a != 0 && $b != 0) {
$c = 4 * ($a + $b);
$d = Math.round($c * 1.1 / $a);
$e = Math.round($c / $b);
}
$sql1 = "UPDATE login SET Punteggio = Punteggio + $d WHERE Risultato = $score";
$a and $b have already been defined. The page returns this error:
Error: SELECT Punteggio, Risultato FROM login
Unknown column 'Math13' in 'field list'
Complete code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link href='https://fonts.googleapis.com/css?family=Montserrat:400,500' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="https://prova2prova1.altervista.org/main1.css" id="theme">
<link rel="shortcut icon" href="images/favicon.ico">
</head>
<body>
<?php
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "prova";
$port = 8889;
$conn = mysqli_init();
if (!$conn)
{
die("mysqli_init failed");
}
if (!mysqli_real_connect($conn,$servername,$username,$password,$dbname,$port))
{
die("Connect Error: " . mysqli_connect_error());
}
$username1 = $_POST['Username'];
$password1 = $_POST['Password'];
$score = $_POST['score'];
$sql = "SELECT Punteggio, Risultato FROM login";
$result = $conn->query($sql);
$a = 0;
$b = 0;
while($row = $result->fetch_assoc()) {
if ($row['Risultato'] == $score) {
$a++;
} else {
$b++;
}
}
if ($a != 0 && $b != 0) {
$c = 4 * ($a + $b);
$d = Math.round($c * 1.1 / $a);
$e = Math.round($c / $b);
}
$sql1 = "UPDATE login SET Punteggio = Punteggio + $d WHERE Risultato = $score";
$sql2 = "UPDATE login SET Punteggio = Punteggio - $e WHERE NOT Risultato = $score";
if ($conn->query($sql1) == TRUE && $conn->query($sql2) == TRUE) {
echo 'I risultati sono stati aggiornati';
} else {
die("Error: " . $sql . "<br>" . $conn->error);
}
$conn->close();
?>
<form method="post" action="admin.php">
<input hidden type="text" name="Username" value="<?php echo htmlspecialchars($username1); ?>">
<input hidden type="password" name="Password" value="<?php echo htmlspecialchars($password1); ?>">
<input type="submit" value="Home">
</form>
</body>
Notice that after all the operations $d is equal to 13. Can anybody help me? Thanks