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 ...
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.
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 ...
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 ...
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 ...
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.
user avatar
  • 3,035
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, ...
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.
user avatar
  • 7,326
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 ...
user avatar
  • 63.4k
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 ($...
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 ...
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. ...
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 ...
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],...
user avatar
  • 63.4k
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 ...
user avatar
  • 63.4k
1 vote

Import for Mashup

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 ...
user avatar
  • 63.4k

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