Hot answers tagged

4

In python, if you want to use a function from an imported library, you have to somehow tell Python that you are going to get that function from which library. I would do: h= cs50.get_int() or import cs50 as cs h= cs.get_int()


2

This while(fgetcsv($file, 500, "\t")) is reading the odd numbered lines. This $csvarray = fgetcsv($file, 500, "\t"); is reading the even numbered lines, which are then inserted into the db.


1

For the sake of completeness, you could also do: from cs50 import get_int h = get_int("Height: ") But directly importing functions (or classes, etc) from a module is not recommended. It'll pollute your global namespace, and soon you'll have no idea where a given function came from. It's much better to stick to importing modules only and using ...


1

You're probably doing this: require("/..includes/config.php"); When you should be doing this: require("../includes/config.php"); If this solves your problem, please click the check mark to accept the answer.


1

I figured it out! It turns out that the issue was not the commented code. The issue was actually the declaration of the while loop. I can confirm that's the case because when I go to PHPMyAdmin I can indeed see all the lines from my data set (in this case US.txt). I am advancing now onto the third out of four to-dos (search.php)


1

Try dump($keywords) to verify that the array data structure contains what you want it to. Also, if preg_split() is giving you trouble here, you may find it easier to use fgetcsv(). Hope this helps.


1

Try this fgetcsv($handle, 0, "\t") instead of this fgetcsv($handle, "\t") Why? Because the second parameter of fgetcsv() is the length of the line. Thus, if you don't explicitly put it there, fgetcsv() will most likely think that your third parameter (delimiter "\t") is in fact the second.


1

You added an extra unwanted ; on this line: if ($handle == FALSE); Remove the semicolon and it will work as wanted.


1

The problem is simple. Look at the offending line: if (!is_readable($sourcefile) { Now check all of your parentheses pairings. This problem with mismatched parentheses occurs several times in your code, but I didn't look much further. No guarantees that there aren't more issues, but this will get you going again. BTW, please spend a little time ...


1

The secret lies in operator precedence and implicit casting. Because the comparison operator !== has a higher precedence than the assignment operator =, $line is cast as a boolean when you use while ($line = fgetcsv($usfile, 0, "\t") !== false). The additional parentheses force the assignment operator to have precedence, thus casting $line as an array.


1

The problem is your input data. Your query is expecting 12 values on every line. The first line in your example has 9. You "lost" the blank columns from the text file, presumably when you converted tab to comma. Your input file should look like this: I 💜 data


1

The problem is your insert query. You are inserting 12 columns, you have 12 ? placeholders, but you are sending 13 arguments. Also, beware: implode returns a string. So you $str_values[0] et. al. will the "individual" characters. fgetcsv returns an array, so $data should be the array you want in your insert.


1

You will get this error PHP Fatal error: Column 'country_code' cannot be null in /home/jharvard /vhosts/pset8/includes/functions.php on line 57 if you use while(!feof($yourfile)) to iterate over the input file. From the Week 4 -> Shorts -> File I/O transcript: Thus, a while loop with the condition (!feof(fp)) might seem like a perfectly ...


1

How are you getting the data from the csv file and populating $file and, by extension, $row? I would start by doing a dump of $row just before the query. I suspect that there is no $row[COUNTRY_CODE], or it could be as simple as you've forgotten to put quotes around "COUNTRY_CODE". ;-) In my code, I used the fgetcsv() function in a while loop and, for ...


1

$lines[12] doesn't exist on $lines as return value from fgetcsv...get rid of "id" as one of your insert values – Mauricio Aguilar Cardenas 7 hours ago Thanks, this has worked. Data seems to stop inputting after the 30th insert. How do you up the limit from 30 in phpMyAdmin? – Kris Valentine 7 hours ago Are you sure it's stopping at 30? 30 happens to be ...


1

The table probably already has values in it or is getting some loaded in successfully, but the problem isn't with what is already in the table. Basically, it looks like something is trying to do an insert with no values, or at least no value or a null value for the country_code column. Your example of the line insert into places(....) VALUES looks like it ...


Only top voted, non community-wiki answers of a minimum length are eligible