Jump to content

Jim R

Members
  • Posts

    988
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by Jim R

  1. I've been asked to allow coaches to upload rosters exported from another source. So I'll be allowing them to upload CSV files. The players' height will be exported as (US measurements) a single column, e.g. 6'4", but I need to have it be two separate columns -- feet and inches. Trying to make it as easy on the coaches as possible, so I'd rather not force them to reformat their file. (Because many won't.) Here is the query I'm currently working with. It works quite well for my test data, but with feet and inches as separate columns. LOAD DATA LOCAL INFILE '$tmp' INTO TABLE a_rosters FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n' IGNORE 1 Lines (uniform,nameFirst,nameLast,position,feet,inches) SET team = '" .$team . "'"; I've dealt a decent amount with exploding an array, putting the results in a Foreach loop and echoing the results. I've not tried to use it before or in the query. (I'm guessing it's not a viable option in a query.) So the files that will be uploaded or emailed to me to upload will have the following columns: uniform, nameFirst,nameLast,position,height ...and I need to turn height into => feet, inches
  2. Simple mistake. That was the issue then for most of this.
  3. Thank you for that. I already had the connection setup and the database set up. That code is still throwing this error: Fatal error: Uncaught Error: Call to a member function prepare() on null in /home2/csi/public_html/wp-content/plugins/csi_stats/csi_roster_process.php:29 Stack trace: #0 {main} thrown in /home2/csi/public_html/wp-content/plugins/csi_stats/csi_roster_process.php on line 14 ($db = myConnect('####'); include("/path to... /con.php"); $db = myConnect('#####'); if ($_SERVER['REQUEST_METHOD']=='POST') { $stmt = $db->prepare("INSERT INTO a_rosters(uniform, nameFirst, nameLast) VALUES (?,?,?)"); $stmt->bind_param('sss', $uniform, $fname, $lname); foreach ($_POST['uniform'] as $k => $uniform) { $fname = $_POST['nameFirst'][$k]; $lname = $_POST['nameLast'][$k]; $stmt->execute(); } } Here is the connection file I use for all my queries... $con = mysqli_connect("localhost","username","password", "csi_wp"); // Check connection if (mysqli_connect_errno()) { //echo "Failed to connect to MySQL: " . mysqli_connect_error(); }
  4. I tried this INSERT inside the loop: foreach ($data as $rec) { // insert record $query = "INSERT INTO a_rosters (uniform,nameFirst,nameLast) VALUES ('$uniform','$fname','$lname')"; It didn't insert anything. I even tried these values: '$rec[$uniform]', '$rec[$fname]','$rec[$lname] Is the below in lieu of all of your previous code? I did that, changing the table name, but it gave me the UNDEFINED error again.
  5. Parse error: syntax error, unexpected ',', expecting ']' in /home2/csi/public_html/wp-content/plugins/csi_stats/csi_roster_process.php on line 46 Line 46 is :: echo '<pre>' . print_r[$data, 1] . '</pre>'; I haven't added the loop yet.
  6. Back to the issue... This is what you gave me in your first response: $data = []; foreach ($_POST['uniform'] as $k => $uniform) { $fname = $_POST['nameFirst'][$k]; $lname = $_POST['nameLast'][$k]; $data[$k] = [$uniform, $fname, $lname]; } After the loop, not thinking I needed it in the loop, I added... $data = implode(",",$data[$k]); echo $data; It echoed the last entry: 10,Steve,Smith => close to what's needed So I placed that inside the loop but got this error: Warning: implode(): Invalid arguments passed in /home2/csi/public_html/wp-content/plugins/csi_stats/csi_roster_process.php on line 43 Changed the $data to $row, and it just produces "Array,Array,Array".
  7. I know, and I did. Each option was giving me the same error. I don't know what the error is really telling me, so I don't know what to change. I don't use pdo, so I read pdo-prepare as preparing to put data I haven't gotten yet into a data table. Then I read the FOREACH loop as getting the $_POST data, which was executed with the $stmt->execute($data); When that didn't work, I put the FOREACH loop you provided earlier. That didn't work. Then I put query in the loop. That didn't work. Just telling you what my thinking was. Elementary...for sure, but that's why I'm here. I don't start posts until after I search here and Stackoverflow. The initial FOREACH loop that you posted, sort of produced what I was looking for. I'm trying to get data from a repeatable field form into a data table. I thought I was doing well to know the implode the array.
  8. I had not. I'm not sure what you mean by it. I notice when I see the print_r of the array that the first one is 0. Not really. I tried it various ways, including with your previous FOREACH loop. Mine is mysqli, but I thought may the pdo-prepare's use was relative to my problem.
  9. Seems if I have unused rows, it will cause issues, or worse, I won't have enough rows. The above query is getting this error:
  10. I need for the User (coaches) to be able to add rows. Teams don't have a set number of players.
  11. How do I echo that out to see what's it's producing? Echoing $data just produced 'array', which I'm sure you would figure. I tried this outside the loop: $data = implode(",",$data[$k]); echo $data; It produced the last set of entries 10,Steve,Smith. I put it inside the loop, and it threw an error. Ultimately, I don't need to see it on screen, just insert it into a table.
  12. I'm wanting coaches/teams to input their roster directly onto the site. Right now it's just three columns: uniform, nameLast,nameFirst I'm using jQuery to add and remove the fields, (once I'm done styling, the form will be a row for each name), and that part appears to be functioning quite well. When it's all done, teams will input anywhere from 10-20 players into the form. It's sent to a .php for processing. I was envisioning the data would come out in rows - uniform, nameFirst, nameLast. Imploding it with *comma* separators, then figuring out how to terminate each line with a |. Instead it's coming out in arrays based on the field. (That makes sense to me as I see the code.) So it's coming out... 3,5,10 Joe, Tim, Steve Johnson, Thomas, Smith I just have this so I could make sure I was at least getting the expected data. $uniform = implode(",",$_POST['uniform']); $fname = implode(",",$_POST['nameFirst']); $lname = implode(",",$_POST['nameLast']); echo $uniform; echo $fname; echo $lname; How do I get it to read: 3,Joe,Johnson 5,Tim,Thomas 10,Steve,Smith Here is the form HTML <form role="form" action="/wp-content/plugins/csi_stats/csi_roster_process.php" method="post"> <div id="myRepeatingFields"> <div class="entry input-group col-xs-3"> <input class="form-control" name="uniform[]" type="text" placeholder="Uni #" /> <input class="form-control" name="nameFirst[]" type="text" placeholder="First Name" /> <input class="form-control" name="nameLast[]" type="text" placeholder="Last Name" /> <span class="input-group-btn"> <button type="button" class="btn btn-success btn-lg btn-add"> <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> </button> </span> </div> </div> <input type="submit" value="Send Roster" name="submit"> </form> Here is the jQuery in case you're curious $(function() { $(document).on('click', '.btn-add', function(e) { e.preventDefault(); var controlForm = $('#myRepeatingFields:first'), currentEntry = $(this).parents('.entry:first'), newEntry = $(currentEntry.clone()).appendTo(controlForm); newEntry.find('input').val(''); controlForm.find('.entry:not(:last) .btn-add') .removeClass('btn-add').addClass('btn-remove') .removeClass('btn-success').addClass('btn-danger') .html(''); }).on('click', '.btn-remove', function(e) { e.preventDefault(); $(this).parents('.entry:first').remove(); return false; }); });
  13. I have all of Host Gator stumped. They don't know why I'm getting an access denied error.
  14. I don't have access to that. I'm talking with someone now. They don't see why I don't have permission to use Load Data. I'll report back. Does the query, however, look good?
  15. I'm working on that. They're telling me I have permission, but I don't. And when you (and my tech) ask me if I have permissions, csi_username has ALL permissions. However, the error shows csi@localhost. Not sure where to check/change csi@localhost.
  16. I have the necessary permissions, according to the tech support, and I know I have file_uploads enabled in php.ini.
  17. I'm not on Linux. I'm accessing my mysql database permissions via my cPanel / phpMyAdmin.
  18. I'm the user running the script. Which command line are you referring to? I checked through cPanel through my host.
  19. I'm the admin (reseller account) so I should have all available privileges. I'm talking to Host Gator now to find out if there is something else.
  20. Where would I check the privileges? I know I had checked whether or not I could write to the folder. I can store the file, but it wasn't uploading the file.
×
×
  • 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.