Jump to content

KevBurgess

Members
  • Content Count

    16
  • Joined

  • Last visited

Community Reputation

0 Neutral

About KevBurgess

  • Rank
    Member

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Hi again Barand, many, many thanks for the tip. The problem has been solved. Here is the code: <!DOCTYPE HTML> <?php $pdo = new PDO ('mysql:dbname=bestelldatenbank;host=localhost;charset=utf8', 'root', ''); unset ($anr); if ($_SERVER['REQUEST_METHOD']=='POST') { if(isset($_POST['artikel'])) { $anr = ($_POST['artikel']); artLoeschen($anr); } else { echo "<p><b>Artikel nummer nicht gesetzt</b></p>"; } } ?> <html lang="de"> <head> <meta charset="utf-8" /> <title>E3_Artikel_Löschen</title> </head> <body> <form method = "POST"> <div> <p> <label for="artikel">Artikel: </label> <select id="artikel" name="artikel" id="artikel"> <?php $sqlSelect = "SELECT anr, name FROM artikel ORDER BY anr ASC"; foreach ($pdo->query($sqlSelect) as $row) { echo "<option value=$row[0]>$row[0] | $row[1]</option>\n"; } ?> </select> <input type = "submit" value = "Datensatz löschen" /> </p> </div> <?php function artLoeschen($anr) { $pdo = new PDO ('mysql:dbname=bestelldatenbank;host=localhost;charset=utf8', 'root', ''); $sqlDelete = 'DELETE FROM artikel WHERE anr = :anr'; if ($stmt = $pdo->prepare($sqlDelete)) { $stmt->bindParam(':anr', $anr); $stmt->execute(); echo "<h2><b>Artikel gelöscht!</b></h2>"; } header("refresh:3"); } $pdo = null; ?> </form> </body> </html> Although I consider the problem resolved I would still appreciate any constructive criticism or advice. There is always room for improvement…. Once again, thank your for your help. Regards, Kev
  2. Hi Barand, many thanks for the tip, it certainly helped. When I click on the "Submit" button though the DELETE statement isn't carried out and the contents of the drop-down list are simply reset. It seems to me as if the variable $anr is not being carried over into the DML statement. Here the altered code: <!DOCTYPE HTML> <?php $pdo = new PDO ('mysql:dbname=bestelldatenbank;host=localhost;charset=utf8', 'root', ''); $anr = ""; if ($_SERVER['REQUEST_METHOD']=='POST') { artLoeschen($anr); } ?> <html lang="de"> <head> <meta charset="utf-8" /> <title>E3_Artikel_Löschen</title> </head> <body> <form method = "POST"> <div> <p> <label for="artikel">Artikel: </label> <select id="artikel" name="artikel"> <?php $sqlSelect = "SELECT anr, name FROM artikel ORDER BY anr ASC"; foreach ($pdo->query($sqlSelect) as $row) { echo "<option value=$row[0]>$row[0] | $row[1]</option>\n"; $anr = $row[0]; } ?> </select> <input type = "submit" value = "Datensatz löschen" /> </p> </div> <?php function artLoeschen($anr) { try { $pdo; } catch (PDOException $error){ die ($error->getMessage()); } if(!isset($_POST[$anr])) { echo "<p><b>Artikel nummer nicht gesetzt</b></p>"; } else { $sqlDelete = $pdo->query("DELETE FROM artikel WHERE anr = :anr"); if ($stmt = $pdo->prepare($sqlDelete)) { $stmt->bindParam(':anr', $anr); $stmt->execute(); echo "<h2><b>Artikel gelöscht!</b></h2>"; } } $pdo = null; } ?> </form> </body> </html> Just for my personal understanding: What actually happens when I click on "Submit"? Is the entire contents of the .php script run or just the dynamic component, in this case the DML statement? Thanks for your help..... Regards, Kev
  3. You are of course right and I forgot to include the line in my code. I had tried to include this call in several places to test the results, all unsuccessful: <?php artLoeschen($anr); ?> Unfortunately I was only guessing where the line should go and that is what is irritating me because nothing I tried seemed to work. Where on earth should this call go in order to submit the form after selecting the appropriate item so the item is deleted? Regards, Kev
  4. Hi all, I am currently learning PHP and have the homework to produce a function that can delete a row in a MySQL database table by clicking on an item in a drop-down menu in a web page. The code I have produced up until now is this: <!DOCTYPE HTML> <html lang="de"> <head> <meta charset="utf-8" /> <title>E3_Artikel_Löschen</title> </head> <body> <form method = "GET"> <?php $anr=""; try { $pdo = new PDO ('mysql:dbname=bestelldatenbank;host=localhost;charset=utf8', 'root', ''); } catch (PDOException $error){ die ($error->getMessage()); } ?> <div> <p> <label for="artikel">Artikel: </label> <select id="artikel" name="artikel"> <?php $sqlSelect = "SELECT anr, name FROM artikel ORDER BY anr ASC"; foreach ($pdo->query($sqlSelect) as $row) { echo "<option value=$row[0]>$row[0] | $row[1]</option>\n"; $anr = $row[0]; } ?> </select> <input type = "submit" value = "Delete row" /> </p> </div> <?php function artLoeschen($anr) { echo "Function called $anr"; if(isset($_GET[$anr])) { $anr = $_GET[$anr]; $sqlDelete = $pdo->query("DELETE FROM artikel WHERE anr = :anr"); if ($stmt = $pdo->prepare($sqlDelete)) { $stmt->bindParam(':anr', $anr); $stmt->execute(); } echo "<h2><b>Artikel gelöscht!</b></h2>"; } } ?> </form> </body> </html> So, I have observed the following when I run the script in a browser: 1. The HTML works as expected and I get a drop-down list with the article number and description of each item in the affected table. 2. I can click on an item in the list and it populates the top item in the drop-down list. 3. When I click delete row, the selected item is not deleted. 4. There are no error messages returned but the function is not executed (at least not as I would like to expect). I have obviously missed something or made a mistake in my code. I would be very grateful for any help...this is driving me mad! :) Regards, Kevin
  5. Hi Alpine, many thanks for your input. It is a cool solution I hadn't considered.... Regards, Kev
  6. If my solution is suboptimal then by all means correct it! For me a forum such as this is one of the most useful tools for learning that there is because experience is a teacher and not simply facts read out of a book. My point is that I (and I am sure many others like me) don't necessarily want the answer thrown at us because that isn't learning. A nudge in the right direction (as in the suggestion offered by my multiplication table example) is prefferable so I work on a (good or not so good) solution and receive appropriate comments and nudges. I appreciate everyones help and comments but I am still going through a quite challenging learning process at the moment that takes me in a completely different direction from PL-SQL and T-SQL and I need to beat my head into submission to make this learning process work.....
  7. Hi Benanamen, many thanks for the solution and of course, the code will be credited accordingly. I do have one request though.... If you see me post a question then I am not looking for a complete solution, just a point at which I can start to find a solution myself. The solution I come to I will post here for the benefit of others. I am very much a programming amateur at the moment and am trying to learn how to code properly and not how to use code from others....that isn't my way..... Regards, Kev
  8. At the moment, not much. I am trying to find a function like INSTRING or SUBSTRING that allows me to extract parts of a string within an element in an array. When I have code written I will post here.....
  9. Sorry, I forgot to mention, this element is a single string with surname and forename and it is this string I am trying to manipulate. Once I understand how to do it with one doing it with all becomes much easier.
  10. Hi Gizmola, thanks for the hint. The syntax as I posted it was indeed wrong and should have been...... $name = array("Burgess, Kevin"); This is then a single string element that needs the forename and surname swapped around and will eventually be part of a new array. If it were two single elements I could have simply referenced the elements using their indexes ( [1], [0] ) to achieve the same result. Solving the problem in SQL I would use REPLACE (to remove the comma), SUBSTRING (to extract each of the two items and put them into variables) and then a SELECT PARAM1 || PARAM2 to display the results. The problem I am having is trying to perform the operation with PHP. A whole new world for me.... Regards, Kev
  11. "Sounds like homework of a sort to me." As I mentioned in my original post, it is indeed homework that I am struggling to find a starting point with. "Why then is your attempt at learning simply to post to this forum (and others?) looking for the answers instead of doing your (hopefully) assigned reading?" As I mentioned in my original post I am not looking for the answer. I am looking for a starting point. I have been looking through the various array functions available in PHP but am still getting to grips with terminology. I am a DBA with 25 years of experience in Oracle, SQL Server, DB2 on iSeries and Exasol and am starting out in programming pretty late. I know where to find DBA answers but as far as programming is concerned still trying to figure out what questions to ask. "If you don't think reading is a good thing or if you are one of the many wanna-be programmers I see on forums such as this who say that they do better with videos and such and don't learn well from reading(!), then let me suggest that programming is not for you. Go back to video games or whatever keeps you occupied if you can't be bothered to learn how to read and experiment with a true learning process. Every one of the languages I learned in my 40 years of IT involved reading a manual as well as other tutorials and class materials as well as hours of practice and thought. If that doesn't interest you then you are on the wrong path." I do think reading is a good thing. Unfortunately by not reading my original post you have shown that you however do not. I do not play video games. I am a serious IT professional learning PHP of a much larger learning curriculum in IT Management. I do use vidoes to supplement my reading (real books by the way.....with paper and my side notes in them.....) and don't consider them bad I can be bothered to learn and read and have invested 100's of Euros in books to do exactly that. And finally...... If all you can do is insult serious profesional people that are simply looking for help then perhaps a forum is not for you..... Regards, Kevin
  12. There are actually 10 values in the array that I will loop through using a foreach function. I put a single value in there to demonstrate the format and what I aim to achieve.
  13. Hi everyone, so, if this looks like homework, it is because it is but I haven't got a clue where to start! I have this array: $name = array["Burgess, Kevin"]; As it is, this is the surname followed by the forename. The task is to display it as "Kevin Burgess". At this point I don't want the whole answer, just a place to begin because I am struggling to find a single function or combination of functions that can help me on my way. Ever grateful for any help..... Regards, Kev
  14. This is indeed the way it should look. Took me a while to square away as well.... Regards, Kev
  15. I am Kevin 47 from the Oracle and SQL Server worlds. I am a newbie PHP guy so I will be posting quite a few questions here..... I am fed up seeing confused, badly presented and linked and irrelevant web interfaces (Enterprise Manager being one of them, Relativity another....) so I have decided I want to learn how to do it better. It's going to be a long road.... Regards, Kev
×
×
  • 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.