I am trying to check if there is a entry from today and if not then add one, if it already exists then not. Current code is:
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql .= "SELECT plusamount AS plustotal, minusamount AS minustotal FROM Juuli WHERE reg_date >= CURRENT_DATE() ORDER BY id DESC";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "It already exists!";
} else {
echo "autowrite should run";
$sql .= "INSERT INTO Juuli(minusamount) VALUES (0); ";
}
$conn->close();
?>
If your SELECT statement is working the way you want it to directly from the database, the following should work. (notice the replacement of .=
with =
)
$sql = "SELECT plusamount AS plustotal, minusamount AS minustotal FROM Juuli WHERE reg_date >= CURRENT_DATE() ORDER BY id DESC";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "It already exists!";
} else {
echo "autowrite should run";
$sql2 = "INSERT INTO Juuli (minusamount) VALUES (0)";
$result2 = $conn->query($sql2);
}
$conn->close();
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments