I am working on a webpage and I want to have a possible delete button which works in the following manner:
- you introduce a country ISO code which you want to delete
- click the button
- if the country has players participating (competitor table, ISO_country_code column) then prints the message that this cannot happen
- if not, deletes the country from country table
I tried in the following way, but I don't know how to create the condition of the second if in order to achieve the appropiate working.
$connect=mysqli_connect("localhost","root","","mydatabase");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
else
{
$result=mysqli_query($connect,"SELECT COUNT(*) FROM competitor
WHERE ISO_country_code='".$_POST['countrycode']."')")
if ($result>0)
{
echo 'The following country is involved with players, so it can not be deleted!</br></br>';
}
else (mysqli_query($connect,"DELETE FROM country WHERE ISO_country_code='".$_POST['countrycode']."'"));
{
echo 'The following country was deleted: '.$_POST["countrycode"]."</br>";
}
}