Jump to content

Barand

Moderators
  • Posts

    24,608
  • Joined

  • Last visited

  • Days Won

    831

Everything posted by Barand

  1. Where to start? If those fields (page_url, link_anchor_text etc) all exist in the form then after the form is posted all those POSTed values will be set. In particular, $_POST['page_url'] will be set so no others will be checked. If $_POST['page_url'] is empty then your SESSION variable will be empty. It needs to contain a valid column name, hence your sql error. You need to be setting the SESSION value to column name, not the content of the form field.
  2. Which of those 34 lines is line 97?
  3. By referencing the file system path to the file or by defining an included files folder in your php.ini file.
  4. Yeah, must be tough. I was only in my 50s when I started learning PHP.
  5. Post the code that's giving the problem. We are not clairvoyant.
  6. You have a couple of options 1 ) Re-format the date in the SQL query when you retrieve the records. EG SELECT DATE_FORMAT(invoice_date_created, '%d.%m.%Y') as invoice_date_created 2 ) Re-format after retrieval in the array $transaction['invoice_date_created'] = date('d.m.Y', strtotime($transaction['invoice_date_created']));
  7. Not quite. var_dump($delta) gives float(0), therefore the first branch needs to be either if ($delta === 0.0) { or if ($delta == 0) {
  8. $templatePrimaryColor = '555555'; echo '<pre>',print_r(hexToHsl($templatePrimaryColor)).'</pre>'; -> Warning: Division by zero in C:\inetpub\wwwroot\test\winuser\noname3.php on line 14
  9. Yes, if all 3 components are equal then $delta is zero, giving a division by zero error.
  10. Your method has a fatal problem with greys (ie when R = G = B)
  11. Restrict your db query with a where clause so you only retrieve the records you want SELECT ... WHERE datecol BETWEEN input_date AND CURDATE() - INTERVAL 1 DAY
  12. Change your query to retrieve the extra item and restructure the $data array to store it. $data = []; $res = $conn->prepare("SELECT name , email -- extra item , month(month) as mno , paid FROM fee WHERE month >= ? ORDER BY name, month "); $res->execute([$start]); foreach ($res as $row) { if (!isset($data[$row['name']])) { $data[$row['name']] = [ 'email' => $row['email'], 'pays' => $empty_array ]; } $data[$row['name']]['pays'][$row['mno']] = $row['paid']; }
  13. It's neither a PHP thing nor a HTML5 thing - it's a plain, old HTML <select> thing. By default, if none of the options have their selected attribute set, the first option is shown as selected.
  14. So the user doesn't have to guess which radio button is for "Male" and which is for "Female" of course.
  15. No. \ is the escape character so needs to be \\ in a dir path. The final \ also needs to be \\ as it is currently escaping the quote at the end of the string. Easier is to use / in paths (even on windows)
  16. When you use <label for="xxx"> then the xxx should be the id of the object being labelled. This is useful with radio buttons or checkboxes and enables the user to click either the object or the label to check or uncheck. In your examples, <label for="yes"> is wrong since "yes" is not an id of anything.
  17. When you get a keyboard that adds indenting and line breaks I'll read your code.
  18. I prefer option 4. EG mysqli_report(MYSQLI_REPORT_ALL|MYSQLI_REPORT_STRICT); $conn = mysqli_connect('localhost', 'someuser', 'wrong_password', 'test');
  19. You actually have choice of mysqli or PDO to replace your mysql.* functions. Don't be fooled into thinking the easier route must mysqli because it's spelt almost the same. PDO is the simpler of the two interfaces.
  20. DATA TABLE: mongoose +----+---------+ | id | testcol | +----+---------+ | 1 | 1 | | 2 | 2 | | 3 | 3 | | 4 | 2,3 | | 5 | 1,4 | | 6 | 2,5 | | 7 | 1,3 | | 8 | 2,4 | +----+---------+ Find records in mongoose where testcol contains 1 or 3 ... mysql> SELECT DISTINCT id, testcol -> FROM mongoose -> JOIN ( -> SELECT 1 as n -> UNION SELECT 3 -> ) nums ON FIND_IN_SET(n, testcol) -> ; +----+---------+ | id | testcol | +----+---------+ | 1 | 1 | | 3 | 3 | | 4 | 2,3 | | 5 | 1,4 | | 7 | 1,3 | +----+---------+ edit: The subquery effectively gives you a temporary table "nums" ... TABLE: nums +---+ | n | +---+ | 1 | | 3 | +---+
  21. $hours_per_day = 6; $total_hours = 20; $days = floor($total_hours / $hours_per_day); $hours_remaining = $total_hours - $days * $hours_per_day; echo "$days days and $hours_remaining hours" ; //--> 3 days and 2 hours
  22. @Jokeh There's a good chance that the question is no longer relevant after nearly 2 1/2 years
  23. Ensure users have to log in before they can vote so you know their user_id. When they vote, store the poll_id and user_id. Put a unique constraint on (poll_id, user_id) so that combination can not be added twice.
  24. Fixed. What editor are you using? <?php include 'functions.php'; // Connect to MySQL $pdo = pdo_connect_mysql(); // If the GET request "id" exists (poll id)... if (isset($_GET['id'])) { // MySQL query that selects the poll records by the GET request "id" $stmt = $pdo->prepare('SELECT * FROM polls WHERE id = ?'); $stmt->execute([$_GET['id']]); // Fetch the record $poll = $stmt->fetch(PDO::FETCH_ASSOC); // Check if the poll record exists with the id specified if ($poll) { // MySQL query that selects all the poll answers $stmt = $pdo->prepare('SELECT * FROM poll_answers WHERE poll_id = ?'); $stmt->execute([$_GET['id']]); // Fetch all the poll anwsers $poll_answers = $stmt->fetchAll(PDO::FETCH_ASSOC); // If the user clicked the "Vote" button... if (isset($_POST['poll_answer'])) { // Update and increase the vote for the answer the user voted for $stmt = $pdo->prepare('UPDATE poll_answers SET votes = votes +1 WHERE id = ?'); $stmt->execute([$_POST['poll_answer']]); // Redirect user to the result page header ('Location: result.php?id=' . $_GET['id']); exit; } } else { die ('Poll with that ID does not exist.'); } } else { die ('No poll ID specified.'); } ?> <?=template_header('Poll Vote')?> <div class="content poll-vote"> <h2><?=$poll['title']?></h2> <p><?=$poll['des']?></p> <form action="vote.php?id=<?=$_GET['id']?>" onSubmit="disable()" method="post"> <?php for ($i = 0; $i < count($poll_answers); $i++): ?> <label> <input type="radio" name="poll_answer" value="<?=$poll_answers[$i]['id']?>" <?=$i == 0 ? ' checked' : ''?>> <?=$poll_answers[$i]['title']?> </label> <?php endfor; ?> <div> <input type="submit" name="submit" value="Vote"> <a href="result.php?id=<?=$poll['id']?>">View Result</a> </div> </form> </div> <?=template_footer()?>
×
×
  • 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.