Jump to content

LeonLatex

Members
  • Posts

    396
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by LeonLatex

  1. What do you call the small articles that are placed as samples or click bait on the front page. That is, e.g. a picture of the main picture in the article + a small extract of the text in the news article. What are these called in English, is it the same as thumbnail?
  2. I used an hour on this. I am not so good at this, so I had to use some extra minutes on it. Hope I am right and you understand it. To edit a database entry using the id, you need to retrieve the id of the record to be edited, and then update the corresponding fields in the database with the new values. Here are the changes you can make to the existing code to enable editing of the database entry using the id: Update the form action to point to the PHP file that will handle the form submission, and pass the id of the record to be edited as a query parameter. For example: <form class="form theme-form" method="POST" action="edit_firm.php?id=<?php echo $firm_id; ?>" autocomplete="off"> Here, edit_firm.php is the PHP file that will handle the form submission, and $firm_id is the id of the record to be edited. Retrieve the id of the record to be edited from the query parameter in the URL. For example: if (isset($_GET['id'])) { $firm_id = $_GET['id']; } else { // handle error if id is not present in URL } Update the SQL query to use the UPDATE statement instead of INSERT, and set the values of the fields to be updated using the form data. For example: $sqleditfirm = "UPDATE firms SET firm_legalname=?, firmbusinessname=?, firmbusiness_addresss=?, firmbusiness_city=?, firmbusiness_state=?, firmbusiness_pin=?, firmbusiness_phone=?, firmbusiness_country=? WHERE id=?"; $stmtditfirm = $conn->prepare($sqleditfirm); $stmtditfirm->bind_param("ssssssssi", $addfirm_legalname, $addfirm_businessname, $addfirm_address, $addfirm_city, $addfirm_state, $addfirm_pin, $addfirm_phone, $addfirm_country, $firm_id); Here, id is the name of the primary key column in the firms table. Retrieve the existing values of the fields for the record to be edited from the database using the id, and prepopulate the form fields with these values. For example: // Retrieve existing values of the fields for the record to be edited $sqlgetfirm = "SELECT * FROM firms WHERE id=?"; $stmtgetfirm = $conn->prepare($sqlgetfirm); $stmtgetfirm->bind_param("i", $firm_id); $stmtgetfirm->execute(); $resultgetfirm = $stmtgetfirm->get_result(); $rowgetfirm = $resultgetfirm->fetch_assoc(); // Prepopulate the form fields with existing values $addfirm_legalname = $rowgetfirm['firm_legalname']; $addfirm_businessname = $rowgetfirm['firmbusinessname']; $addfirm_address = $rowgetfirm['firmbusiness_addresss']; $addfirm_city = $rowgetfirm['firmbusiness_city']; $addfirm_state = $rowgetfirm['firmbusiness_state']; $addfirm_pin = $rowgetfirm['firmbusiness_pin']; $addfirm_country = $rowgetfirm['firmbusiness_country']; $addfirm_phone = $rowgetfirm['firmbusiness_phone']; Note that you also need to handle any errors that may occur during the editing process. For example, you can display an error message if the record with the specified id is not found in the database.
  3. Sorry for my English, but to save time I had to use GT on some of my postings. Usually, I don't do that. Sometimes it works well, and sometimes it doesn't. I have read thru your code a couple of times, and I think I understand it. If I don't, please put me on the right track again. I am only a human and not a machine. The possibility of being wrong is there, and I'm not very good at this, but I try. I have not read thru the other answers in the thread, so sorry if I step on someone's toes. Shot in the blind.... From your code, it seems you are using checkboxes to select multiple items for deletion from a table. Right? However, you mentioned that only the first checkbox is working, even when you select the last checkbox. One issue I see with your code is that you are using the same name attribute for all the checkboxes, which means they will all have the same value when they are submitted. This could be causing the problem you are experiencing. To fix this issue, you need to give each checkbox a unique name attribute value that corresponds to the product ID for that particular item. You can do this by appending the product ID to the name attribute value of each checkbox using square brackets, like this: <input type='checkbox' name='check_list[<?= $prod_id ?>]' value='<?= $prod_id ?>' > In the above code, we are appending the product ID to the name attribute value of the checkbox using PHP. This will ensure that each checkbox has a unique name attribute value that corresponds to the product ID for that particular item. Then, in your PHP code, you can loop through the $_POST['check_list'] array to get the product IDs of the selected items, like this: if(!empty($_POST['check_list'])) { foreach($_POST['check_list'] as $prod_id) { // Delete the item with this product ID } } By doing this, you should be able to select multiple items for deletion using checkboxes and delete them successfully.
  4. Will flex and flexbox mean the same as setting up the web page with X number of DIV boxes and then controlling them with CSS3. So, if you imagine that the DIV boxes are parallel both vertically and horizontally (like making a grid), they will be adjusted with CSS and form the intended and planned design. Because then you probably also want to make the DIV boxes different in position and size. Is there something here that I am wrong with my assumptions? Is this partly the intention/principle of the flexbox? Much of this I already know, but I need to have it confirmed, because what I read online and in books are so different. It is possible that I am misunderstanding because bad English etc, but a confirmation of what is right and correction of what is wrong would be nice. I have read the PHP documentation as sugested to.
  5. First of all, I must apologize for asking a question on a Q&A forum. Sorry for that, but thanks at the same time for the help I get. So to what this thread is really about. You are absolutely right Requinix, When you are logged in, the link or button on the navigation bar should be activated, while it should be deactivated/overshadowed when you are not logged in, and I do it in the following way. I only saw now that I have forgotten something important. Namely to add what is written in the header.php file. It is probably very important and I include that too. After I've pasted it in I'll show what I'm doing in trying to get this to work after I had to reconstruct the entire script after breaking what was done for me in an attempt to improve and add features myself, and which therefore turns out to be wrong. By the way. I include the navigation bar too below header.php header.php <?php session_start(); $ROOT = str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']) . '/'; $HOST = 'http://' . $_SERVER['HTTP_HOST'] . '/'; $disabl1 = isset($_SESSION['member_id']) ? '' : 'w3-disabled'; $disabl2 = isset($_SESSION['member_id']) && isset($_SESSION['isadmin']) ? '' : 'w3-disabled'; $log_btn = isset($_SESSION['member_id']) ? 'Logg ut' : 'Logg inn'; const SYSNAME = 'Management System'; const PAGETITLE = 'Welcome'; const HELPBUTTON = ""; ?> Nav bar <NAV> <div class='w3-bar w3-light-gray w3-margin-bottom' style='height: 39px'> <a id='nav-members' href='<?=$HOST?>index.php' class='w3-bar-item w3-button'>Hjem</a> <a id='nav-register' href='<?=$HOST?>register.php' class='w3-bar-item w3-button'>Registrering</a> <a id='nav-members' href='<?=$HOST?>members.php' class='w3-bar-item w3-button'>Medlemmer</a> <a id='nav-marina' href='<?=$HOST?>marina.php' class='w3-bar-item w3-button'>Båtplass</a> <a id='nav-invoice' href='<?=$HOST?>invoice/invoice.php' class='w3-bar-item w3-button'>Faktura</a> <a id='nav-login' href='<?=$HOST?>login.php' class='w3-bar-item w3-button w3-right'><?=$log_btn?></a> </div> </NAV> Here's what I tried to get it to work: <?=$disabl1?> or <?=$disabl2?> All this do is too write "w3-disabled" on the navigation button. Will say, I do it the same way as it is done with login.php link in the navbar above. Another error is that I have administrative rights regardless of whether I am logged in or not. I don't understand what I'm doing wrong or where, and after all the work I had to reconstruct the system, I don't dare touch it too much.
  6. Barry made this, and the intention is to have the link activated only when logged in as a user or admin. I don't remember how it was set up. Somehow this is controlling the login users rights depending on the email address, which is the username. I paste the sessions from the header.php, members.php and marina.php and the rest of the sites containing the content. I also attached other things related to the log in such as e.g. database etc. If there is something you feel I have forgotten, I hope you will ask. I only try to keep the post as short as possible. I want the user rights to be right again. Do you understand what I mean? Can you help me?, please members.php session. <?php session_start(); $ROOT = str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']) . '/'; $HOST = 'http://' . $_SERVER['HTTP_HOST'] . '/'; $disabl1 = isset($_SESSION['member_id']) ? '' : 'w3-disabled'; $disabl2 = isset($_SESSION['member_id']) && isset($_SESSION['isadmin']) ? '' : 'w3-disabled'; $log_btn = isset($_SESSION['member_id']) ? 'Logg ut' : 'Logg inn'; const SYSNAME = 'Nikolivia Maraina Management System'; const PAGETITLE = 'Velkommen'; const HELPBUTTON = ""; ?> marina.php session. <?php session_start(); include $ROOT.'db_inc.php'; $pdo = pdoConnect(); $loggedin = $_SESSION['member_id'] ?? 0; unset( $_SESSION['member_id'], $_SESSION['isadmin']); if ($loggedin) { header("Location: {$HOST}marina.php"); exit; } ?> The database part with the records containing the user rights level settings. Here comes some of the HTML/PHP. login.php <?php session_start(); include $ROOT.'db_inc.php'; $pdo = pdoConnect(); $ROOT = str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']) . '/'; $HOST = 'http://' . $_SERVER['HTTP_HOST'] . '/'; $loggedin = $_SESSION['member_id'] ?? 0; unset( $_SESSION['member_id'], $_SESSION['isadmin']); if ($loggedin) { header("Location: {$HOST}members.php"); exit; } $msg = ''; if ($_SERVER['REQUEST_METHOD']=='POST') { $res = $pdo->prepare("SELECT password , member_id , admin FROM member WHERE email = ? "); $res->execute([ $_POST['email'] ]); $row = $res->fetch(); if ($row && password_verify($_POST['password'], $row['password'])) { $_SESSION['member_id'] = $row['member_id']; if ($row['admin'] == 1) { $_SESSION['isadmin'] = 1; } header("Location: {$HOST}members.php"); exit; } else $msg = "<div class='w3-panel w3-red w3-padding'><p>Ugyldig innlogging</p></div>"; } ?> <?php session_start(); $ROOT = str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']) . '/'; $HOST = 'http://' . $_SERVER['HTTP_HOST'] . '/'; $disabl1 = isset($_SESSION['member_id']) ? '' : 'w3-disabled'; $disabl2 = isset($_SESSION['member_id']) && isset($_SESSION['isadmin']) ? '' : 'w3-disabled'; $log_btn = isset($_SESSION['member_id']) ? 'Log out' : 'Login'; const SYSNAME = 'Management System'; const PAGETITLE = 'Login'; const HELPBUTTON = ""; ?> <!DOCTYPE html> <html lang='en'> <head> <title><?=SYSNAME?></title> <meta http-equiv='Content-Type' content='text/html; charset=utf-8'> <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.1/css/all.css"> <link href='css/footer.css' rel='stylesheet' type="text/css"> </head> <body> <div class='w3-content w3-card-4 w3-light-gray' style='margin-top: 100px;'> <div class='w3-panel w3-black w3-padding'> <?=SYSNAME?> - <?=PAGETITLE?> </div> <?=$msg?> <form method='POST' class='w3-padding'> <label>E-mail</label> <input type='text' class='w3-input w3-border' name='email'> <label>Password</label> <input type='password' class='w3-input w3-border' name='password'> <br> <button type='submit' class='w3-button w3-blue w3-right'>Logg Inn</button> <br><br><br> </form> </div> </body> </html>
  7. I am working on and trying to further develop the member and invoice system for another project. Barand was the one who helped me with this and developed it for me from the start, but since I can't get in touch with him anymore I have to ask you guys. In any case, I can no longer see him online either here on PHP Freaks or on Skype. I guess I haven't seen him online since mid-March. so I need some help to look at what I need to activate on the server, and how this should be configured so that a pdf invoice is automatically sent by email when a new registration occurs on the website. To start somewhere... Barand integrated a mail system to have it to automatic send mail to one to three people simultaneously when a new member registration is sent from the registration form. I can't remember what he used when he developed this, I know it isn't the usual php sendmail in linux. I cant find any trace of it in the scripts. Can you imagine what it is?
  8. Thank you for a very good answer that was very explanatory and comprehensive. Thanks, requinix 😊👌👍
  9. I'm browsing different documentation for HTML5, and I'm going to familiarize myself with version 5 of HTML, and the version I was familiar with was HTML 4.01. It's not easy to catch everything when you have to constantly look up and down, back and forth to find answers, because there is a lot that is new for me. So, I'm asking here. These examples: <HEADER> <NAV> <MAIN> <FOOTER> . What are these called? Are they only called a TAG(s), or do they have a special/own name?
  10. Yes, I have found that too, but I don't know of another place to do this or another way to do it. I am stuck as a duck.
  11. Yes, I re-wrote the whole script (file). That fixed all the problems, but not this one.
  12. I need help deciphering this error message. I can't figure it out myself and I can't see anything wrong with it. Can you see where the error(s) are? Error message in browser: ArticleWebsite.php: DatabaseTable.php:
  13. Why does your error script report itself? It does so on line 3. <?php error_reporting(E_ALL); ini_set('display_errors', '1');
  14. Yes, I understand that. But does it add only the www.domain, domain, or the full path from which directory on the server it is placed inside the file?
  15. What's the differences between include and include __DIR__ . '/../includes/DatabaseConnection.php';
  16. Thanks. Hope this will bring me on the right path.
  17. Ok, here it is. Thanks for the CTRL+Z. I re-wrote the script, but it was more errors than the first one, so I post the old one. The same errors and amount of them. <?php class databaseTable { public function __construct(private PDO $pdo, private string $table, private string $primaryKey) { } public function find($field, $value) { $query = 'select * FROM `' . $this->table . '` WHERE `' . $field . '` = :value'; $values = [ 'value' => $value ]; $stmt = $this->prepare($query); $stmt->execute($values); return $stmt->fetchAll(); } public function findAll() { $stmt = $this->pdo->prepare('SELECT * FROM `' . $this->table . '`'); $stmt->execute(); return $result->fetchAll(); } public function total() { $stmt = $this->pdo->prepare('SELECT COUNT(*) FROM `' . $this->table . '`'); $stmt->execute(); $row = $stmt->fetch(); return $row[0]; } public function save($record) { try { if (empty($record[$this->primaryKey])) { unset($record[$this->primaryKey]); } $this->insert($record); } catch (PDOException $e) { $this->update($record); } } private function update($values) { $query = ' UPDATE `' . $this->table .'` SET '; foreach ($values as $key => $value) { $query .='`' . $key . '`= :' . $key . ','; } $query = rtrim($query, ','); $query .= ' WHERE `' . $this->primaryKey . '` = :primaryKey'; //Set the primary key variable $values['primaryKey'] = $values['id']; $values = $this->processDates($values); $stmt = $his->pdo->prepare($query); $stmt->execute($values); } private function insert($values) { $query = 'INSERT INTO `' . $this->table . '`('; } foreach ($values as $key => $value) { $query .= '`' . $key . '`,'; } $query = rtrim($query, ','); $query .= ') values ('; foreach ($values as $key => $value) { $query .= ':' . $key . ','; } $query = rtrim($query, ','); $query .= ')'; $values = $this->processDates($values); $stmt = $this->pdo->prepare($query); $stmt->execute($values); } public function delete($field, $value) { $values = [':value' => $value]; $stmt = $this->pdo->prepare('DELETE FROM`' . $this->table . '` WHERE `' $field . '` = :value'); $stmt->execute($values); } function processDates($values) { foreach ($values as $key => $value) { if ($value instanceof DateTime) { $values[$key] = $value->format('Y-m-d'); } } return $values; } }
  18. Yes, i am on my way. I post it as text when i am finished.
  19. I tried to upgrade. It didn't work. I try to write the script again.
  20. No, I still get an HTTP ERROR 500
  21. Do you mean DW doesn't like it? So there is nothing wrong? The script doesn't run in the browser when I run this in the top: <?php error_reporting(E_ALL); ini_set('display_errors', '1'); PHP 7.2 is running on the server. I can upgrade to 8.1, but then i will get a lot of problems with other scripts and sites. As I told cyberRobot, the script won't run in the browser. I try with this one too: <?php error_reporting(E_ALL); ini_set('display_errors', '1');
  22. I can't find the error. In VSC the error is only on only line 17. In DW, which the image is from, the error is on multiple lines (as you can see on the image. Can someone please help me and tell me where/what the error is? I have checked the PHP reference manual + websites. They all tell me teres nothing wrong.
  23. What I want to do now have i done before, but now I can't. I want logo_bar to be 100% wide from margin left to margin right. Now there is a gap on the right side. The 2nd. is the translate_div with the google translate inside. I want it to be aligned 20px from the right margin, but now it won't. Sure, I am doing something wrong, but after trying a lot of different things I give up. Can you see what I am doing wrong? <body> <div class="header_container"> <div class="logo_bar"> <div class="logo_div"> <div class="translate_div"> <div id="google_translate_element"></div> <script type="text/javascript"> function googleTranslateElementInit() { new google.translate.TranslateElement({pageLanguage: 'en'}, 'google_translate_element'); } </script> <script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script> </div> </div> </div> ---------------------------------------------------------------------- div.header_container { background-color: #033333; height: 83px; width: 100%; padding-top: 0px; margin-top: 0px; } div.logo_bar { display: flex; background-color: #033333; width: 100%; height: 47px; } div.logo_div { background-image: url("../images/logo_bg_original.png"); width: 300px; height: 35px; margin-top: 3px; } div.translate_div { display: inline; width: 300px; height: 35px; margin-left: 20px; }
  24. Great Maxxd. This will be useful 😊 Thanks 👍
  25. OK, after much troubling I found the missing link, called error. I had a CSS class in my body tag + I have misunderstood the use of <HEADER>, <NAV>, <MAIN> and <FOOTER>, like some of you have tried to make me understand. I can't put the header inside the main tag f.ex. Now everything is OK, so far. I hope I don't meet more problems like this. It makes so much more problems, and makes me use so much unnecessary use of time. Thank you for trying and helping me with advice and solutions😊👍
×
×
  • 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.