-
Posts
24,566 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
Trying to get data from form with Repeatable fields into MySQL...
Barand replied to Jim R's topic in MySQL Help
Process 1a, with the multiple form records, is the only process that involves arrays. Once you've got the data into temp_csv, it's just a couple of queries. -
Trying to get data from form with Repeatable fields into MySQL...
Barand replied to Jim R's topic in MySQL Help
-
Trying to get data from form with Repeatable fields into MySQL...
Barand replied to Jim R's topic in MySQL Help
That is what I said Process 2 does. INSERT IGNORE INTO player (...) SELECT ... FROM temp_csv; -
Trying to get data from form with Repeatable fields into MySQL...
Barand replied to Jim R's topic in MySQL Help
The write the data from the form into the temp csv file. Then the process then on is exactly same, regardless of the data source. -
Trying to get data from form with Repeatable fields into MySQL...
Barand replied to Jim R's topic in MySQL Help
Process 1 is a LOAD DATA LOCAL INFILE ... query to put the csv data into a temporary table. Process 2 inserts player data from the temp table (new records only). Process 3 matches the temp data with the player data using the names to get the player ids and inserts records into the roster table. -
Trying to get data from form with Repeatable fields into MySQL...
Barand replied to Jim R's topic in MySQL Help
It should -
Trying to get data from form with Repeatable fields into MySQL...
Barand replied to Jim R's topic in MySQL Help
-
Trying to get data from form with Repeatable fields into MySQL...
Barand replied to Jim R's topic in MySQL Help
if $player is a boolean (ie false) then the prepare failed. Check column names etc. Good to see you're finally putting that data into the player table instead of the roster table. -
Then read this
-
That will only report php errors. Put this at the beginning of your code, preferably just before you connect to mysql mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);
-
Why don't you output mysql's error messages and make it easier for you (and us)
-
Then it didn't find a record matching your data conditions.
-
No, just the query to use UNIX_TIMESTAMP() instead of CURDATE() since that is how your expire date is stored.
-
Then you definitely need to read @requinix's reply.
-
What is the data type of the "expires" column in your table?
-
I would refer you to earlier replies.
-
Trying to get data from form with Repeatable fields into MySQL...
Barand replied to Jim R's topic in MySQL Help
you problem with line 35... $termID = $con->lastInsertID(); <---- line 35 ... is that lastInsertID() is PDO method and you are using mysqli. You therefore need $termID = $con->insert_id; It won't return the last id inserted by stmt2 until it has actually inserted a record. You are calling it before any inserts have been made. It needs to be called between the execution of stmt2 and the execution of stmt3. -
curdate() is a mysql function. Read the replies.
-
Your query contains only 1 placeholder (?) but you bind 2 parameters The second parameter is unnecessary if you replace $currentDate in your query with the sql function CURDATE(). EG $sql = "SELECT * FROM reset_password WHERE selector=? AND expires >= curdate()";
-
Simple php calendar plugin trying to add linkable dates
Barand replied to OldGrim's topic in PHP Coding Help
There was no specification of how it's supposed to be. I just threw in the ability to change the month as an extra. If you want it to behave differently, change it. -
Simple php calendar plugin trying to add linkable dates
Barand replied to OldGrim's topic in PHP Coding Help
I've made a skeleton mockup of your "filtered.php" which works with this version of my code included in it. blog_filtered.php <?php include 'db_inc.php'; $pdo = pdoConnect('test'); $post_id = $_GET['post_id'] ?? 0; $res = $pdo->prepare("SELECT post_title , post_body , date_format(from_unixtime(posted), '%D %M %Y at %l:%i %p') as posted FROM db_grims_blog_post WHERE post_id = ? "); $res->execute([$post_id]); $blog = $res->fetch(); $title = $blog['post_title'] ?? ''; $posted = $blog['posted'] ?? ''; $content = $blog['post_body'] ?? ''; ?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Example</title> <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> </script> </head> <body> <div class='w3-container w3-black'> <div class="w3-row-padding"> <div class='w3-col m9'> <div class='w3panel w3-yellow w3-padding'> <h3><?=$title?></h3><br> <h6><?=$posted?></h6> </div> <div class='w3-container'> <p><?=$content?></p> </div> </div> <div class='w3-col m3'> <?php include 'blog_calendar.php' ?> </div> </div> </div> </body> </html> blog_calendar.php <?php // include 'db_inc.php'; $pdo = pdoConnect(); $today = new DateTime( $_GET['date'] ?? '' ); $prev = (clone $today)->modify('-1 month')->format('Y-m-d'); $next = (clone $today)->modify('+1 month')->format('Y-m-d'); $caption = $today->format('F Y'); $this_month = $today->format('n'); $day1 = (clone $today)->modify("first day of this month"); $queryStart = $day1->format('Y-m-d'); if ($day1->format('w') != 0) { $day1->modify('last Sunday'); } $dayN = (clone $today)->modify('last day of this month'); $queryEnd = $dayN->format('Y-m-d'); if ($dayN->format('w') != 6) { $dayN->modify('next sunday'); } $period = new DatePeriod($day1, new DateInterval('P1D'), $dayN); // calendar display dates ## ## get this month's blogs ## $blogs = []; $res = $pdo->prepare("SELECT post_id , date(from_unixtime(posted)) as day , post_title FROM DB_GRIMS_BLOG_POST WHERE date(from_unixtime(posted)) BETWEEN ? AND ? ORDER BY posted "); $res->execute( [ $queryStart, $queryEnd ] ); foreach ($res as $r) { if (!isset($blogs[$r['day']])) { $blogs[$r['day']] = []; } $blogs[$r['day']][] = $r; } ## ## Functions ## function calheads() { $out = '<tr>'; $days = [ 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' ]; foreach ($days as $d) { $out .= "<th abbr='$d' title='$d'>{$d[0]}</th>"; } return $out; } function caldata($per, $mth, &$blogs, $date) { $i = 0; $out = ''; foreach ($per as $d) { if ($i%7 == 0) { if ($out != '') $out .= "</tr>\n"; $out .= "<tr>"; } ++$i; $dno = $d->format('d'); $cls = $link = $title = $datablog = ''; $dbArr = []; if ($d->format('n') != $mth) { $cls .= 'blank '; } else { $cls .= 'daycell '; if ($d->format('Y-m-d') == date('Y-m-d')) $cls .= 'today '; if (isset($blogs[$d->format('Y-m-d')])) { $dayblogs = $blogs[$d->format('Y-m-d')]; $cls .= 'active '; if (count($dayblogs)==1) { $title = $blogs[$d->format('Y-m-d')][0]['post_title']; $dno = "<a href='blog_filtered.php?post_id={$blogs[$d->format('Y-m-d')][0]['post_id']}&date=$date'>$dno</a>"; } else { $title = join("\n", array_column($dayblogs,'post_title')); $cls .= 'multiblog '; foreach ($dayblogs as $dba) { $dbArr[$dba['post_id']] = $dba['post_title']; } $datablog = json_encode($dbArr); } } } $out .= "<td class='$cls' title='$title' data-blogs='$datablog'>$dno</td>\n"; } $out .= "</tr>\n"; return $out; } ?> <!-- <!DOCTYPE html> <html> <head> <meta http-equiv="content-language" content="en"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Example calendar</title> <meta name="creation-date" content="12/06/2020"> --> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script> <script type='text/javascript'> $().ready( function() { $(".multiblog").click( function() { var blogs = $(this).data('blogs') var date = $("#cal-date").val() $("#blogmenu").hide() $("#blogmenu").position({"Top":0, "Left":0}) $("#blogmenu").html("<b>Select blog:</b><br>") $.each(blogs, function(k,v) { // $("#blogmenu").append("<p><a href='https://whisperwillow.net/infusions/grims_blog/filtered.php?post_id="+k+"&date="+date+"'>"+v+"</a></p>") $("#blogmenu").append("<p><a href='blog_filtered.php?post_id="+k+"&date="+date+"'>"+v+"</a></p>") }) var pos = $(this).position() $("#blogmenu").css("display","inline-block") $("#blogmenu").offset( {"top": pos.top+25, "left": pos.left} ) }) $("#blogmenu").click( function() { $("#blogmenu").html("<b>Select blog:</b><br>") $("#blogmenu").hide() $("#blogmenu").position({"Top":0, "Left":0}) }) }) </script> <style type='text/css'> body, table { font-family: arial, sans-serif; font-size: 14px; } table { border-collapse: collapse; width: 63%; margin: 50px auto; } caption { background-color: #A91723; color: #FFF; padding: 5px; text-align: center; font-size: 16px; } th { background-color: #5F8874; color: #FFF; padding: 2px; } td { background-color: #000; color: #FFF; padding: 2px; text-align: center; font-weight: 600; height: 22px; } td.active { background-color: #e3e3e3; color: #0000FC; } td.blank { background-color: #CCC; color: #FFF; } td.today { background-color: #07ABF6; } a { text-decoration: none;; } a:hover { text-decoration: underline;; } #navbtn1, #navbtn2 { font-weight: 600; color: #FFF; text-decoration: none; } #navbtn1 { float: left; } #navbtn2 { float: right; } #blogmenu { display: none; font-size: 14px; position: absolute; top: 0; left: 0; max-width: 200px; background-color: #FCF8E8; color: #000; padding: 4px; border: 2px solid #006EFC; } .multiblog { cursor: pointer; } </style> <!-- </head> <body> --> <input type='hidden' id='cal-date' value='<?=$today->format('Y-m-d')?>'> <table border='1'> <caption> <a id='navbtn1' href='?date=<?=$prev?>'><</a> <?=$caption?> <a id='navbtn2' href='?date=<?=$next?>'>></a> </caption> <thead> <?=calheads()?> </thead> <tbody> <?=caldata($period, $this_month, $blogs, $today->format('Y-m-d'))?> </tbody> </table> <div id='blogmenu'></div> <!-- </body> </html> --> -
Trying to get data from form with Repeatable fields into MySQL...
Barand replied to Jim R's topic in MySQL Help
Quite right, sorry about that. The bind statement should be $stmt2->bind_param('ssss', $fname, $lname, $fname, $lname); -
So if my surname were "Smythe-Jones" you would change it to SmytheJones if I tried to register?
-
Trying to get data from form with Repeatable fields into MySQL...
Barand replied to Jim R's topic in MySQL Help
You could, but it's easier to do it the PHP code if ($_SERVER['REQUEST_METHOD']=='POST') { $stmt1 = $db->prepare("INSERT INTO a_rosters(uniform, nameFirst, nameLast) VALUES (?,?,?)"); $stmt1->bind_param('sss', $uniform, $fname, $lname); $stmt2 = $con->prepare("INSERT INTO wp_terms(name, slug) VALUES (?,?)"); $stmt2->bind_param('ss', $name, $slug); foreach ($_POST['uniform'] as $k => $uniform) { $fname = $_POST['nameFirst'][$k]; $lname = $_POST['nameLast'][$k]; $name = "$fname $lname"; $slug = strtolower("$fname-$lname"); $stmt1->execute(); $stmt2->execute(); } } To do it in the query you would $stmt2 = $con->prepare("INSERT INTO wp_terms(name, slug) VALUES (concat(?,' ',?), lower(concat(?,'-',?)) ); $stmt2->bind_param('ssss', $name, $slug, $name, $slug); -
Simple php calendar plugin trying to add linkable dates
Barand replied to OldGrim's topic in PHP Coding Help
Then how are you able to click "Prev" as in previous post?