delete and update of user records
Moderator: General Moderators
Re: delete and update of user records
how do I get a value in checkbox?
Re: delete and update of user records
now I am getting no error with foreach, however I have no value read in checkbox. $_POST['checkbox'] just echos "array" - no value. Therefore there is no value to do delete
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: delete and update of user records
Is this after you have submitted the form?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Re: delete and update of user records
when the page opens with no checkbox values I get the error. When I click a checkbox the page opens again but this time with no error (as it now has a value) but no delete happens.
Re: delete and update of user records
the error message I fixed with a simple if else
I'm wondering if the problem is not with my form tabs?
Code: Select all
<?php
if ($_POST['checkbox']) {
foreach ($_POST['checkbox'] as $value) {
$id = $value;
$sql = "DELETE * FROM recommendations WHERE idnum = '". $id ."' ";
$deletesql = mysql_query($sql);
}
}
else
{
}Code: Select all
<form action="myrecommendations.php" method="post" enctype="application/x-www-form-urlencoded" name="myrecommendations" target="_self" id="myrecommendations">- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: delete and update of user records
Maybe. Remove everything except the action and method attributes and see what happens.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Re: delete and update of user records
nothing happens 
Re: delete and update of user records
can anyone help?
This is what I am echoing out from my delete query.
DELETE * FROM recommendations WHERE idnum = '.43.'
I can't delete anything.I think it is because of the ". ." that it is not recognising the query, How can I strip them (the ..)?
Here is my delete script
This is what I am echoing out from my delete query.
DELETE * FROM recommendations WHERE idnum = '.43.'
I can't delete anything.I think it is because of the ". ." that it is not recognising the query, How can I strip them (the ..)?
Here is my delete script
Code: Select all
<?php
if ($_POST['checkbox']) {
foreach ($_POST['checkbox'] as $value) {
$id = $value;
$sql = "DELETE * FROM recommendations WHERE idnum = '". mysql_real_escape_string($id) ."' ";
echo $sql.'<br>';
$deletesql = mysql_query($sql);
}
}
else
{
}
?> - social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: delete and update of user records
Are you storing the value with the two periods i.e .43. in the database?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Re: delete and update of user records
no. I have tried to get rid of them on the query but I haven't been able to.
Re: delete and update of user records
try,
Code: Select all
$id = $value;
$escaped_id = mysql_real_escape_string($id);
$sql = "DELETE FROM recommendations WHERE idnum = '$escaped_id';";
Last edited by Neilos on Mon Jan 31, 2011 4:10 pm, edited 1 time in total.
Re: delete and update of user records
It actually worked with this:
Is this good practise? It works anyway, however I hope it does not leave security problems.
The only problem I have now is to get the page to automatically refresh on form submit
Code: Select all
foreach ($_POST['checkbox'] as $value) {
$id = $value;
$sql = "DELETE FROM recommendations WHERE idnum = '$id' ";The only problem I have now is to get the page to automatically refresh on form submit
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: delete and update of user records
Any 'input' into the database should be passed through mysql_real_escape_string. You can also check if the value is numeric but since you preset the value it's up to you.
Glad it's finally working 
Code: Select all
$sql = "DELETE FROM recommendations WHERE idnum = '". mysql_real_escape_string($id) ."' ";“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Re: delete and update of user records
thankyou very much for all your help and ideas.
Do you know how I can get the delete input to refresh the page? - metatags? Or would I be better to bounce around 2 pages - send to delete2.php and if they want to delete another entry send back to delete1.php. etc.
Do you know how I can get the delete input to refresh the page? - metatags? Or would I be better to bounce around 2 pages - send to delete2.php and if they want to delete another entry send back to delete1.php. etc.
Re: delete and update of user records
just so you know how this finished:
did the job. Together with moving the whole block of PHP to the top of the page ... in the headers. I had put this under the html form. A mistake many may be making - the forums are full of this error, none of which seemed to provide a clear answer.
It's all great now
Code: Select all
headers("location:URL.php")It's all great now