MySQL, insert not working

All I'm trying to do is ready from a text file of male first names and write each name to table called "namesmale", and my PHP goes through without any errors, and yet, no names are being written. What am I doing wrong??? Here is the code:

    $db = DB::getPDOConnection(); // gets a db connection
    
    $sql1 = " DROP TABLE IF EXISTS namesmale; "; // This works
    $sql2 = " CREATE TABLE namesmale ( " .
           " id INT(11) NOT NULL AUTO_INCREMENT, " .
           " firstname VARCHAR(30) NOT NULL, " .
           " PRIMARY KEY (id)) "; // This works, too
    
    $db->query($sql1); // This query works
    $db->query($sql2); // This query works
    
    $handle = fopen("../namesmale.txt", "r"); // The text file with list of male names
    while(!feof($handle)) {
        $line = fgets($handle); // Read a name
        $db->exec("INSERT INTO 'namesmale' ('firstname;) VALUES ('" . $line . "');"); // insert into database, THIS IS NOT WORKING!
    }
    fclose($handle); //close text file
    $db = null; // close db connection

Open in new window


Can anyone please tell me what I'm doing wrong? Thanks.
elepilAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
I think your punctuation is wrong.  This...
"INSERT INTO 'namesmale' ('firstname;) VALUES ('" . $line . "');"

Open in new window

Should be this:
"INSERT INTO `namesmale` (`firstname`) VALUES ('" . $line . "')"

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
elepilAuthor Commented:
DOH! Didn't see that semicolon after firstname. Thanks!
0
Dave BaldwinFixer of ProblemsCommented:
You're welcome!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.