Jump to content

Jim R

Members
  • Posts

    988
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by Jim R

  1. This is working to get the $playerID $pid = $con->prepare("SELECT id FROM a_players WHERE nameFirst = ? AND nameLast = ? AND schoolID = ?"); $pid->bind_param('sss',$fname,$lname,$schoolID); In the FOREACH loop $pid->execute(); $pid->bind_result($playerID); $pid->fetch(); But now, it's not inputting into the roster table, a query which has been unchanged.
  2. changed fetchColumn() to fetch_assoc(). Same error. The code I've added to this is a direct application to what you suggested from the start.
  3. This is the code you gave me back on page 2 of this topic. I've used the same format (and tried a couple of others) based on what you sent. It worked...except as I've tried to get the $playerID.
  4. $pid = $con->prepare("SELECT id FROM a_players WHERE nameFirst = ? AND nameLast = ? AND schoolID = ?"); $pid->bind_param('sss',$fname,$lname,$schoolID); In the FOREACH loop: $pid->execute(); $playerID = $pid->fetchColumn(); <-- line 95
  5. I have tried $pid->fetch(); As well as fetchAll, fetchColumn. Same error. (Or whatever the syntax is) Using this as a reference: https://phpdelusions.net/pdo
  6. Here is the total code as it stands: if(isset($_POST['submit'])) { $schoolID = $_POST['school']; $varsity = $_POST['varsity']; $season = $_POST['season']; // This uploads it into the Rosters table $player = $con->prepare("INSERT INTO a_players(schoolID,nameFirst,nameLast,feet,inches,grade,position,varsity) VALUES (?,?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE feet = ?, inches = ?, varsity = ? "); $player->bind_param('sssssssssss',$schoolID,$fname,$lname,$feet,$inches,$grade,$position,$varsity,$feet,$inches,$varsity); $pid = $con->prepare("SELECT id FROM a_players WHERE nameFirst = ? AND nameLast = ? AND schoolID = ?"); $pid->bind_param('sss',$fname,$lname,$schoolID); $roster = $con->prepare("INSERT INTO a_rosters(schoolID, playerID, uniform, varsity, season) VALUES (?,?,?,?,?)"); $roster->bind_param('sssss', $schoolID, $playerID, $uniform, $varsity, $season); foreach ($_POST['uniform'] as $k => $uniform) { $fname = $_POST['nameFirst'][$k]; $lname = $_POST['nameLast'][$k]; $feet = $_POST['feet'][$k]; $inches = $_POST['inches'][$k]; $grade = $_POST['grade'][$k]; $position = $_POST['position'][$k]; $player->execute(); $pid->execute(); echo $playerID; $roster->execute(); } It all works except getting the $playerID. I'll try a subquery with $roster now.
  7. I have, otherwise I wouldn't have known this. I have tried both bind_param and bindparam. They both yield the same error. I have tested the query on my database with values typed in. It produces what it should. I know the values are being passed to the variables because they're working through the other queries. I'm showing you what i've tried, and where the current code sits. Also, keep in mind, this path was your suggestion in the beginning of this topic. It worked, except for what I found I needed, which was the previously established ids. I have since amended one of the queries to involve a Duplicate Key Update. Easy enough. So I'm not without learning. This one seems to evade us.
  8. Evidently mixing name and positional placeholders is frowned upon. Sitting now with this code: $pid = $con->prepare("SELECT id FROM a_players WHERE nameFirst = ? AND nameLast = ? AND schoolID = ?"); $pid->bindparam($fname,$lname,$schoolID); <-- line 59 With $pid->execute(); in the FOREACH loop Getting this error:
  9. It is, but it has been working for other queries/prepares. Everything has worked up to this point. I can set up a PDO connection if you think it will matter. $player = $con->prepare("INSERT INTO a_players(schoolID,nameFirst,nameLast,feet,inches,grade,position,varsity) VALUES (?,?,?,?,?,?,?,?)"); $player->bind_param('ssssssss',$schoolID,$fname,$lname,$feet,$inches,$grade,$position,$varsity); $pid = $con->query("SELECT id FROM a_players WHERE nameFirst = :fname AND nameLast = :lname AND schoolID = :schoolID"); $roster = $con->prepare("INSERT INTO a_rosters(schoolID, playerID, uniform, varsity, season) VALUES (?,?,?,?,?)"); $roster->bind_param('sssss', $schoolID, $playerID, $uniform, $varsity, $season); $player and $roster work for how they're currently written. Just need to get the playerID out of $player to use in $roster. Remember, I had it working to get the most recently added ID. I had the wrong command but was close.
  10. The above is just in lieu of a subquery in the $player statement.
  11. I"m not really throwing code. That's just going back to what was working...before I realized I needed to playerID of previously entered players and not just the new ones. I've tried the $con->query version. I've tried a lot. Not sure why the query isn't providing a value. Earlier, I accidentally echoed the SELECT with the variables $fname, $lname and $schoolID, and it echoed the correct values. It literally printed "SELECT id FROM a_players WHERE nameFirst = 'Joe' AND nameLast = 'Smith' and schoolID = 44" Right now I have this: boolean error.
  12. This didn't insert any data, and those variables have been up there the whole time. Check page 2. include("/path/to/con.php"); if(isset($_POST['submit'])) { $schoolID = $_POST['school']; $varsity = $_POST['varsity']; $season = $_POST['season']; // This uploads it into the Rosters table $player="INSERT IGNORE INTO a_players (nameFirst,nameLast,feet,inches,schoolID,grade,varsity) SELECT nameFirst , nameLast , feet , inches , school_id , grade , varsity FROM temp_csv"; $roster="INSERT IGNORE INTO a_rosters(schoolID, playerID, uniform, varsity, season) SELECT t.schoolID, p.playerID t.uniform, t.varsity, t.season FROM temp_csv t JOIN a_players p ON t.nameFirst = p.nameFirst AND t.nameLast = p.nameLast AND t.schoolID = p.schoolID";
  13. So this works with one exception. It doesn't get the playerID as needed. $player = $con->prepare("INSERT INTO a_players(schoolID,nameFirst,nameLast,feet,inches,grade,position,varsity) VALUES (?,?,?,?,?,?,?,?)"); $player->bind_param('ssssssss',$schoolID,$fname,$lname,$feet,$inches,$grade,$position,$varsity); $roster = $con->prepare("INSERT INTO a_rosters(schoolID, playerID, uniform, varsity, season) VALUES (?,?,?,?,?)"); $roster->bind_param('sssss', $schoolID, $playerID, $uniform, $varsity, $season); foreach ($_POST['uniform'] as $k => $uniform) { $fname = $_POST['nameFirst'][$k]; $lname = $_POST['nameLast'][$k]; $feet = $_POST['feet'][$k]; $inches = $_POST['inches'][$k]; $grade = $_POST['grade'][$k]; $position = $_POST['position'][$k]; $name = "$fname $lname"; $slug = strtolower("$fname-$lname"); $taxonomy = "post_tag"; $player->execute(); $roster->execute(); echo $playerID; <-- just to check as we go Need to figure out $playerID
  14. I had to change columns to fit, table names. You said it wasn't what you sent instead of just showing me I had a t instead of a p. So I stripped out other code and just applied what you typed. I don't know why you went away from what was working, when what I need instead of insert_id was any id. Even when this method wasn't throwing an error, it wasn't inserting the rows. So I stripped it back just what you typed outside of changing the table names and getting rid of the column level.
  15. include("/path/to/con.php"); if(isset($_POST['submit'])) { $schoolID = $_POST['school']; $varsity = $_POST['varsity']; $season = $_POST['season']; // This uploads it into the Rosters table INSERT IGNORE INTO a_players (nameFirst,nameLast,feet,inches,schoolID,grade,varsity) SELECT nameFirst , nameLast , feet , inches , school_id , grade , varsity FROM temp_csv; INSERT IGNORE INTO a_rosters(schoolID, playerID, uniform, varsity, season) SELECT t.schoolID, p.playerID t.uniform, t.varsity, t.season FROM temp_csv t JOIN a_players p ON t.nameFirst = p.nameFirst AND t.nameLast = p.nameLast AND t.schoolID = p.schoolID; }
  16. I see now, but that doesn't address the error I received and still received after changing the t to p.
  17. I had to alter the table names, remove the level column. INSERT IGNORE INTO a_players (nameFirst,nameLast,feet,inches,schoolID,grade,varsity) SELECT nameFirst , nameLast , feet , inches , school_id , grade , varsity FROM temp_csv; INSERT IGNORE INTO a_rosters(schoolID, playerID, uniform, varsity, season) SELECT t.schoolID, t.playerID t.uniform, t.varsity, t.season FROM temp_csv t JOIN a_players p ON t.nameFirst = p.nameFirst AND t.nameLast = p.nameLast AND t.schoolID = p.schoolID;
  18. This is what I had for what you posted, but it didn't insert the data: (you originally had level and varsity as columns. It's just varsity. I changed level to varsity to avoid a future issue) $players = " INSERT IGNORE INTO a_players (nameFirst,nameLast,feet,inches,schoolID,grade,varsity) SELECT nameFirst , nameLast , feet , inches , school_id , grade , varsity FROM temp_csv;"; $roster = "INSERT INTO a_rosters(schoolID, playerID, uniform, varsity, season) SELECT t.schoolID, t.playerID t.uniform, t.varsity, t.season FROM temp_csv t JOIN a_players p ON t.nameFirst = p.nameFirst AND t.nameLast = p.nameLast AND t.schoolID = p.schoolID";
  19. Getting this error now: Current code: $player = $con->prepare("INSERT INTO a_players(schoolID,nameFirst,nameLast,feet,inches,grade,position,varsity) VALUES (?,?,?,?,?,?,?,?)"); $player->bind_param('ssssssss',$schoolID,$fname,$lname,$feet,$inches,$grade,$position,$varsity); $playerID = $con->prepare("SELECT id FROM a_players WHERE nameFirst = '" .$fname. "' AND nameLast = '" .$lname. "' AND schoolID = " .$schoolID. ""); $roster = $con->prepare("INSERT INTO a_rosters(schoolID, playerID, uniform, varsity, season) VALUES (?,?,?,?,?)"); $roster->bind_param('sssss', $schoolID, $playerID, $uniform, $varsity, $season); This is in the FOREACH LOOP: $player->execute(); $playerID->execute(); $roster->execute(); <-- line 90
  20. But it didn't insert any rows.
  21. I tried this: $playerID = $con->prepare("SELECT id FROM a_players WHERE p.nameFirst = :fname AND p.nameLast = :lname AND schoolID = :schoolID"); $playerID->execute(['fname' => $fname, 'lname' => $lname, 'schoolID' => $schoolID]); $playerIDget = $playerID->fetch(); Same error. Does the boolean aspect of that error mean I'm not getting any results? I know it's recognizing the variables because I'm echoing them out.
  22. I also tried adding fetch(): $playerID = $con->query("SELECT id FROM a_players WHERE p.nameFirst = '" .$fname. "' AND p.nameLast = '" .$lname. "' AND schoolID = " .$schoolID. "")->fetch(); But it threw an error.
  23. I'm saying when I figured out I was missing how to get the playerID of previously entered players, I was looking at subqueries and trying to figure out how to do that in what you provided earlier, which was otherwise working very well. I was trying this: $player->execute(); $playerID = $con->query("SELECT id FROM a_players WHERE p.nameFirst = '" .$fname. "' AND p.nameLast = '" .$lname. "' AND schoolID = " .$schoolID. ""); $roster->execute(); echo $playerID; <-- this is here just to see if playerID is being passed. So far, no. I'm not getting any errors. 🙃
  24. That would be this code: $roster = $con->prepare("INSERT INTO a_rosters(schoolID, playerID, uniform, varsity, season) VALUES (?,?,?,?,?)"); $roster->bind_param('sssss', $schoolID, $playerID, $uniform, $varsity, $season);
  25. What we had before was working, other than not getting the playerID of players already entered in a_players. I didn't necessarily know how to make the insert / select query align with the bind_param.
×
×
  • 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.