How to delete a record from a table??
The table holds a.o. a field name "datum"
The field would look like
01-01-2011
12-02-2011
and so on
The forms can only be opened by logged in users
In the form I can load the userdetails by
In the HTML I can create a selectbox showing all the dates
So far so good, but how can make the submit button to delete that specific record from the table.
The table holds a.o. a field name "datum"
The field would look like
01-01-2011
12-02-2011
and so on
The forms can only be opened by logged in users
In the form I can load the userdetails by
<?php
$user =& JFactory::getUser();
$db =& JFactory::getDBO();
$query = "SELECT * FROM `jos_comprofiler` WHERE `id` = ".$user->id."; ";
$db->setQuery($query);
$user_info = $db->loadObject();
?>
In the HTML I can create a selectbox showing all the dates
So far so good, but how can make the submit button to delete that specific record from the table.
Hi SPABO,
In the onsubmit code
Bob
In the onsubmit code
<?php
$datum = JReqest::getString('datum', '', 'post');
if ( $datum ) {
$db =& JFactory::getDBO();
$query = "
DELETE
FROM `#__some_table`
WHERE `dataum` = '$datum' ;
";
$db->setQuery($query);
$db->query();
}
?>
Bob
Hi Bob,
When I select the date ("Wedstrijddatum"), it removes ALL THE RECORDS with this Wedstrijddatum!!!!!
And it should remove teh logged in member!!
This is the button "submit"
This is the on-submit code
When I select the date ("Wedstrijddatum"), it removes ALL THE RECORDS with this Wedstrijddatum!!!!!
And it should remove teh logged in member!!
This is the button "submit"
<div class="form_item">
<div class="form_element cf_button">
<input value="Verstuur" name="button_11" type="submit" /><input type="reset" name="reset" value="Herstel"/>
</div>
<div class="cfclear"> </div>
</div>
This is the on-submit code
<?php
$datum = JRequest::getString('datum', '', 'post');
if ( $datum ) {
$db =& JFactory::getDBO();
$query = "
DELETE
FROM `jos_chronoforms_PITCHenPUTT`
WHERE `Wedstrijddatum` = '$datum' ;
";
$db->setQuery($query);
$db->query();
}
?>
<p>
U bent nu verwijderd etc
</p>
Hi SPABO,
Sorry, I don't do mind-reading and I can’t guess what the input names in your form and table are. You need to adapt the code sample to suit your form.
Bob
Sorry, I don't do mind-reading and I can’t guess what the input names in your form and table are. You need to adapt the code sample to suit your form.
Bob
Dear Bob
In teh table there are several fields, a.o "Wedstrijddatum", input DD/MM/YYYY
And there are several different dates
When opening the "delete-form", two fiels are by default (firstname and email)
Based on this code at the beginning of HTML
Next to this there is a selectpart, to "pick" the "Wedstrijddatum"
So, wehen the user selects a wedstrijddatum and pushes submit, the whole reocord should be removed from the table
In teh table there are several fields, a.o "Wedstrijddatum", input DD/MM/YYYY
And there are several different dates
When opening the "delete-form", two fiels are by default (firstname and email)
Based on this code at the beginning of HTML
<?php
$user =& JFactory::getUser();
$db =& JFactory::getDBO();
$query = "SELECT * FROM `jos_comprofiler` WHERE `cf_user_id` = ".$user->id."; ";
$db->setQuery($query);
$user_info = $db->loadObject();
?>
Next to this there is a selectpart, to "pick" the "Wedstrijddatum"
So, wehen the user selects a wedstrijddatum and pushes submit, the whole reocord should be removed from the table
Hi SPABO,
I've given you the form of code you need. Now it's up to you to make that do what you want.
Bob
I've given you the form of code you need. Now it's up to you to make that do what you want.
Bob
Hi Bob
I want the the record from the table whereby teh RECORD contains
Userid (of the loggedin user) AND the selected Wedstrijddatum
With the code you provided it deletes ALL the records where the selected Wedstrijddatum is in
Really hope you can help
I want the the record from the table whereby teh RECORD contains
Userid (of the loggedin user) AND the selected Wedstrijddatum
With the code you provided it deletes ALL the records where the selected Wedstrijddatum is in
Really hope you can help
I fully understand what you are saying
I have now in On submif after enmail this code:
But this ADDS new records instead of deleting!
I have now in On submif after enmail this code:
<?php
$datum = JRequest::getString('Wedstrijddatum', '', 'post');
if ( $datum ) {
$db =& JFactory::getDBO();
$query = "
DELETE
FROM `jos_chronoforms_PITCHenPUTT`
WHERE `id` = ".$user->id."; ";
$db->setQuery($query);
$db->query();
}
?>
But this ADDS new records instead of deleting!
Hi SPABO,
That code doesn't add any records but if you have a DB Connection on the form that might.
Bob
That code doesn't add any records but if you have a DB Connection on the form that might.
Bob
Hi Bob
Correct, the table connection was active!
After removing the DB connection, it does not add records, but also does not DELETE records
Correct, the table connection was active!
After removing the DB connection, it does not add records, but also does not DELETE records
Hi SPABO,
Then there is a problem with the MySQL query, most probably with the WHERE clause.
Bob
Then there is a problem with the MySQL query, most probably with the WHERE clause.
Bob
I don't think so Bob, because it worked with the initial code (when all the records with the datum were removed)
Dear Bob
Whatever I try, I can't make it work.
Really hope you can spare a few mins to assist, where am I going wrong??
Pls find the HTML code and the code On submit after
HTML
On submit code
Whatever I try, I can't make it work.
Really hope you can spare a few mins to assist, where am I going wrong??
Pls find the HTML code and the code On submit after
HTML
<?php
$user =& JFactory::getUser();
$db =& JFactory::getDBO();
$query = "SELECT *
FROM `jos_comprofiler`
WHERE `id` = ".$user->id."; ";
$db->setQuery($query);
$user_info = $db->loadObject();
?>
<div class="form_item">
<div class="form_element cf_dropdown">
<label class="cf_label" style="width: 150px;">Wedstrijddatum</label>
<select class="cf_inputbox validate-selection" id="select_1" size="1" title="U bent vergeten de datum aan te geven!" name="Wedstrijddatum">
<option value="">Datum</option>
<option value="23-01-2011">23-01-2011</option>
<option value="20-02-2011">20-02-2011</option>
<option value="20-03-2011">20-03-2011</option>
</select>
<a class="tooltiplink" onclick="return false;"><img height="16" border="0" width="16" class="tooltipimg" alt="" src="components/com_chronocontact/css/images/tooltip.png"/></a>
<div class="tooltipdiv">Wedstrijddatum :: Vul hier de juiste wedstrijddatum in</div>
</div>
<div class="cfclear"> </div>
<div class="form_item">
<div class="form_element cf_textbox">
<label class="cf_label" style="width: 150px;">Email</label>
<input name="email" type="primarelyemailaddress" id="email" size="30" maxlength="150" VALUE="<?php $user = &JFactory::getUser();echo $user->email;?>" disabled="disabled" </div>
<input name="email" type="hidden" id="email" VALUE="<?php $user = &JFactory::getUser();echo $user->email;?>" </div>
<div class="cfclear"> </div>
</div>
<div class="form_item">
<div class="form_element cf_button">
<input value="Verstuur" name="button_11" type="submit" /><input type="reset" name="reset" value="Herstel"/>
</div>
<div class="cfclear"> </div>
</div>
On submit code
<?php
$datum = JRequest::getString('Wedstrijddatum','', 'post');
if ($datum) {
$db =& JFactory::getDBO();
$query = "DELETE
FROM `jos_chronoforms_PITCHenPUTT`
WHERE `id` = ".$user->id." ;
";
}
?>
Hi SPABO,
From a quick look $user isn't defined in the OnSubmit code so $user->id will be empty or create a PHP error.
Bob
From a quick look $user isn't defined in the OnSubmit code so $user->id will be empty or create a PHP error.
Bob
Tried this, but no sucess
<?php
$datum = JRequest::getString('Wedstrijddatum','', 'post');
if ($datum) {
$db = &JFactory::getDBO();
$user = &JFactory::getUser();
$query = "DELETE
FROM `jos_chronoforms_PITCHenPUTT`
WHERE `cf_user_id` = ".$user->cf_user_id." ;
";
}
?>
Bob, Your answers put me on wrong legs..
I'm not sure what you want to tell me now.
Pls be aware I'm a nono on PHP!
Where am I thinking in the wrong direction.....
I'm not sure what you want to tell me now.
Pls be aware I'm a nono on PHP!
<?php
$user =& JFactory::getUser();
$datum = JRequest::getString('Wedstrijddatum','', 'post');
if ($datum) {
$db = &JFactory::getDBO();
$query = "DELETE
FROM `jos_chronoforms_PITCHenPUTT`
WHERE `cb_lidcode` = ".$user->cb_lidcode."; ";
}
?>
Where am I thinking in the wrong direction.....
Hi SPABO,
I'm telling you to stop and think carefully what the code you are writing does and what you want it to do. If it is beyond your PHP, MySQL & Joomla! skills then there are plenty of good documents that you can learn from, or you can find someone to work with you.
What will not work -- unless you are very lucky -- is to randomly stick variables into a code snippet in the hope that it will do what you need.
Bob
I'm telling you to stop and think carefully what the code you are writing does and what you want it to do. If it is beyond your PHP, MySQL & Joomla! skills then there are plenty of good documents that you can learn from, or you can find someone to work with you.
What will not work -- unless you are very lucky -- is to randomly stick variables into a code snippet in the hope that it will do what you need.
Bob
This is working now, but still struggling with the "validation"
It shoeld not run is there are no matching data in the table
It shoeld not run is there are no matching data in the table
<?php
$user_info = JRequest::getString('cb_lidcode', '', 'post');
$datum = JRequest::getString('Wedstrijddatum', '', 'post');
if ($datum)
{
$db =& JFactory::getDBO();
$query = "
DELETE
FROM `jos_chronoforms_PITCHenPUTT_TESTEN`
WHERE `cb_lidcode` = '$user_info' and `Wedstrijddatum`= '$datum'";
$db->setQuery($query);
$db->query();
}
?>
This topic is locked and no more replies can be posted.