I'm having a problem in deleting a row from one of my table in my mySQL DB. Below you can see the code I am using (This is the php file, which is calling the SQL query from a form):
<?php
echo '
<form style="padding-left:30px; padding-bottom:40px; padding-top:10px; clear:both;" action="deletingcontactgroups.php">
<label><strong>Please Select A Group to Delete!</strong></label>
<select name="dropdown" style="float:left;">
<option value="">Select a Contact Group:</option>';
$con=mysqli_connect("localhost","username","password","my_db");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM ContactsGroup");
while($row = mysqli_fetch_array($result)) {
echo '<option value="' . $row["GroupName"] . '">' . $row["GroupName"] . '</option>';
echo "<br>";
}
echo '<input type="submit" style="clear:both; float:left; margin-left: 300px;">';
echo '</form>';
mysqli_close($con);
?>
This is the data in the file deletingcontactgroups.php :
<?php
$con=mysqli_connect("localhost","username","password","my_db");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$groupname = mysqli_real_escape_string($con, $_POST['dropdown']);
$sql = "DELETE FROM `bulletproofaccounting`.`ContactsGroup` WHERE `ContactsGroup`.`GroupName` = '" . $groupname . "' LIMIT 1;";
mysqli_query($sql);
echo "1 record has been deleted successully!!!";
mysqli_close($con);
?>
I looked into various tutorials, but nothing is helping. Any help would be highly appreciated!
EDIT!!! I'm extremely sorry for the typo, but the quotation marks were actually placed during concatenation of the variable $sql. Sorry for the trouble.