Probably a beginners mistake but my PHP $_POST seems to delete part of the value which is submitted via the form.
The code below works perfectly fine if $company_name is just one word (without spaces) but for values with spaces it does not seem to work...
I use the following code to submit the form:
In the dropdown menu the values are correctly shows as (for example) 'Company in Country Y'.
However, when I then use the posted value in the deletecompany.php file only the first word ('Company') would come through.
I use the following code in deletecompany.php:
if (isset($_POST["company_name"])){
// delete from database
$company_name = $_POST["company_name"];
$delete_company = "DELETE FROM company WHERE company_name='$company_name'";
if ($conn->query($delete_company) === TRUE) {
echo $company_name . " has been deleted successfully!";
} else {
echo "Error: " . $delete_company . "
" . $conn->error;
}
}
The output of the deletecompany.php page would be 'Company has been deleted succesfully!' but in fact no Company is actually deleted since there is no such value in the relevant MYSQL colomn (there is a value 'Company in Country Y').
Does $_POST automatically delete part of the value or do I miss something else here?
Thanks!
Answer
Your option values have not been correctly enclosed, hence why the browser is only taking the first word of the string.
echo "";
You need to enclose the option value, like this:
echo "";
No comments:
Post a Comment