Hot answers tagged

4 votes
Accepted

Why can't I use get_int in python

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 ...
Ha Tran's user avatar
  • 74
2 votes
Accepted

pset8, import. Only even row numbers from US.txt are being written to db

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.
DinoCoderSaurus's user avatar
1 vote

Why can't I use get_int in python

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 ...
MestreLion's user avatar
1 vote
Accepted

Pset8, Mashup, import, i have been seen this error

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 ...
Yuri Laguardia's user avatar
1 vote

Pset 8 Mashup Import Issue (fgetcsv returns empty array)

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 ...
AdiKhajuria's user avatar
1 vote

Pset8 - Import using PHP array

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.
hotwebmatter's user avatar
  • 3,050
1 vote

Pset8 import undefined offset notice

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, ...
Yuri Laguardia's user avatar
1 vote
Accepted

PSET8: fopen() not working for import

You added an extra unwanted ; on this line: if ($handle == FALSE); Remove the semicolon and it will work as wanted.
ChrisG's user avatar
  • 7,376
1 vote
Accepted

How to fix "PHP parse error" when running import?

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 ...
Cliff B's user avatar
  • 68.2k
1 vote

ERROR RESOLVED:PHP Fatal error: Column 'country_code' cannot be null in /home/jharvard/vhosts/pset8/includes/functions.php on line 57

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 ($...
DinoCoderSaurus's user avatar
1 vote
Accepted

PSET8 import undefined offsets and fatal error

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 ...
DinoCoderSaurus's user avatar
1 vote
Accepted

PSET8 import fatal error

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. ...
DinoCoderSaurus's user avatar
1 vote

PHP Fatal error: Column 'country_code' cannot be nullPHP Fatal error: Column 'country_code' cannot be null

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 ...
DinoCoderSaurus's user avatar
1 vote

PHP Fatal error: Column 'country_code' cannot be nullPHP Fatal error: Column 'country_code' cannot be null

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],...
Cliff B's user avatar
  • 68.2k
1 vote
Accepted

pset8 query function

$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 ...
Cliff B's user avatar
  • 68.2k

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