Jump to content

Da9L

Members
  • Posts

    8
  • Joined

  • Last visited

Everything posted by Da9L

  1. And by registration setup i mean.. I've developed a PHP application that i wish to sell. So i need some sort of way to make sure that my system only works if the user is registered / has paid for the app.. This is an area i have no experience in so im looking for advice and best practices. Im thinking an API key that the user only gets when they pay, and the system then validates this key up against a server of mine, when its entered into the app. But should this check happen everytime the app is run or a specific task is run ? Or is there another more appropriate way to do this ? Thanks ! EDIT: Lol sorry for title typo
  2. Sorry about the mysql query it was just a quick out the head placeholder.. I've decided to not use checkboxes as i simply cant figure out how to . So now im going to try this instead.. When each line has been generated from the search results a form with two buttons will also be generated..
  3. Hello .. I need some help with this .. I have a user database where an admin can add/delete users and search for them on a website.. What i want is a possibility to update user details.. Its a little hard to explain but heres a screenshot As you can see i have some fields that is editable .. Those fields are generated based on what you search for on the page before.. On the top row you can see two buttons: "Slet"(delete) and "Gem" (save) .. On the first collum all to the left you can see a checkbox.. As it is now, a user can mark this checkbox and click delete, which deletes the marked users from the database .. What i want also is if a user has edited some information in the fields AND marked the checkbox to the left of the edited fields AND clicked "Gem" (save) the rows with the marked users should be updated with the new information in the database.. I just have no idea how to do this.. Heres the code for the delete button: if($_POST['delete']){ $idList = join (',', array_map('intval', $_POST['checkbox'])); $sql = "DELETE FROM `users` WHERE `userid` IN ($idList)"; mysql_query($sql); echo "* - De markerede brugere blev slettet!"; include "includes/redirection_admin.php"; } At first i thought it would be as simple as to just change the sql query to UPDATE instead but that doesnt work .. This is what i have made: $idList = join (',', array_map('intval', $_POST['checkbox'])); $sql = "UPDATE `users` SET `fornavn`='$userid' IN '$fornavn', `efternavn` IN '$efternavn', `cprnr` IN '$cprnr', `adresse` IN '$adresse', `postnr` IN '$postnr', `by` IN '$by', `tlfnr` IN '$tlfnr', `email` IN '$email', `userid` IN '$userid' WHERE `userid` IN ($idList)"; mysql_query($sql); echo "* - De markerede brugere fik opdateret deres oplysninger!"; But that doesnt work .. The fields doesnt change Can anyone assist ?
  4. Thanks a bunch ! This seems to work.. Im sorry you had to give me the "spoonfed" version . Im new to this and have a lot to learn! I just still dont understand why it works, but i can look that up my self in the php manual for the syntax The line i dont get is this $idList = join (',', array_map('intval', $_POST['opgaver_chkbx'])); But i will look that up .. thanks a million !
  5. Yes i figured that out sorry.. But im still not able to figure out how to make it working..
  6. So i should name the checkboxes after their ID in MySQL which would look like this $opgaver_fra_db = mysql_query("SELECT * FROM `opgaver`"); echo '<form method="post" action="">'; echo '<input type="submit" value="Slet opgaver" name="delete"/><p>'; while ($chkbx_values = mysql_fetch_array($opgaver_fra_db)) { echo '<input type="checkbox" value="'.$chkbx_values['id'].'" name="opgaver_chkbx"> '.$chkbx_values['opgave'].'</br>'; } Should i also use the variable in the "name" field of the checkbox ? If i try the above it seems that the boxes get each their own id, but how do i go about deleting the checked checkboxes then?
  7. but the problem is that i use an array to list the checkboxes too .. and from the looks of it it looks like you list the checkboxes as fixed in the above.. as you can see in the first code box i listed thats where the checkboxes are generated on the page.. how would i give the individual id's ?
  8. Hey everyone ! First post here and i hope im doing this right ! I've begun to learn PHP and MySQL .. Its going fine untill further but im currently stuck .. What i need is that a user is able to create "tasks".. Those tasks will be stored in a MySQL database table and shown to this user with a checkbox next to them. I've managed to create this, but what i want now is a way to delete those that has been checked after the user clicks a button. I thought this was rather simple but i simply cant figure out how to do it.. Easiest way would be to show you my code.. So here it is: <?php $opgaver_fra_db = mysql_query("SELECT * FROM `opgaver`"); echo '<form method="post" action="opgave_delete.php">'; echo '<input type="submit" value="Slet opgaver" name="delete"/><p>'; while ($chkbx_values = mysql_fetch_array($opgaver_fra_db)) { echo '<input type="checkbox" value="'.$chkbx_values['opgave'].'" name="checkbox"> '.$chkbx_values['opgave'].'</br>'; } echo '</form>'; ?> The above code seems to work great.. A list is shown with checkboxes form what has been created. Heres some code on how to create a new task: $nyopgave = $_POST['opgave_navn']; include 'includes/connection.php'; $tjek_query_opgaver_exists = mysql_query("SELECT * FROM opgaver WHERE opgave = '$nyopgave'") or die(mysql_error()); $opgave_exists = mysql_fetch_array($tjek_query_opgaver_exists); if($opgave_exists['opgave'] > 0) { echo "! - Opgaven er allerede oprettet i systemet!"; } else { $opretopgave = "INSERT INTO opgaver (`opgave`) VALUES ('$nyopgave')"; $opretopgave_query = mysql_query($opretopgave); if($opretopgave_query) { echo "* - Opgaven blev oprettet korrekt!"; include "includes/redirection_admin.php"; } else { "! - Opgaven blev IKKE oprettet korrekt!"; } } This also works great and it is shown in the list that is then loaded when redirected back to the admin page.. The code that loads the list is the code shown first. But heres what i cant get to work .. I need to be able to delete multiple rows when those checkboxes have been selected and a button is clicked.. But i dont know how to do this .. This is the code i've tried so far..: <?php if(isset($_POST['delete'])){//check to see if the delete button has been pressed include "includes/connection.php"; if(isset($_POST['checkbox'])){ //check to see if any boxes have been checked $num = 0;//used to count the number of rows that were deleted $box = $_POST['checkbox']; while (list ($key,$val) = @each ($box)) { //loop through all the checkboxes $num++; $sqldel="DELETE FROM logins WHERE id='$val'";//delete any that match id $resdel=mysql_query($sqldel);//send the query to mysql } //print the logs that were deleted echo"$num record(s) have been deleted."; } else{//no boxes checked echo "No records selected."; } } ?> I dont think this is how you would do it as it doesnt work at all .. Any suggestions ?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.