I'm building a full HTML/PHP/CSS website for learning purposes as it's my first website. my site subject is private trainers [gym~workout~sport] and I added packages to the database, only trainers can add these packages and also update them to change inside information.
There are 3 plans: Free, Silver, Gold, to update the package the trainer must his username+password. if it's correct is should show this message: Update successful if the username or password wrong it should show this message: Could not update
The problem is when he choosing plan and entering the right user and password, it's working and also showing the success message, but if he entering the wrong user or password, it's still showing the success message but not updating in the database.
here is the PHP:
<?php
//Create connection to the database.
$host="localhost"; // Host name
$dbusername="root"; //username
$dbpassword=""; //username password
$dbname="proil"; //db name
// Connect to server and select database.
$con = mysqli_connect($host,$dbusername,$dbpassword,$dbname);
//Input posted data.
$zehut = $_POST["id"];
$answer = $_POST['pickclass'];
$pass = $_POST['pass'];
$count=0;
if ($answer == "free") {
$query = "UPDATE trainer_packages AS b
INNER JOIN trainer_d AS g ON b.trainer_pack_id = g.id
SET b.package__name= 'free'
WHERE b.trainer_pack_id = '$zehut' and g.pass ='$pass' ";
$count=$count+1;
}
if ($answer == "silver") {
$query = "UPDATE trainer_packages AS b
INNER JOIN trainer_d AS g ON b.trainer_pack_id = g.id
SET b.package__name= 'silver'
WHERE b.trainer_pack_id = '$zehut' and g.pass ='$pass' ";
$count=$count+1;
}
if ($answer == "gold") {
$query = "UPDATE trainer_packages AS b
INNER JOIN trainer_d AS g ON b.trainer_pack_id = g.id
SET b.package__name= 'gold'
WHERE b.trainer_pack_id = '$zehut' and g.pass ='$pass' ";
$count=$count+1;
}
//Run SQL query
mysqli_query($con, $query) or die ("ERROR: Cannot do insert ".mysqli_error($con));
if (mysqli_query($con, $query)) {
echo "Update successful.";
} else {
echo "Could not update: " . mysqli_error($con);
}
//Close the SQL connection.
mysqli_close($con);
?>