elepil
asked on
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:
Can anyone please tell me what I'm doing wrong? Thanks.
$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
Can anyone please tell me what I'm doing wrong? Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You're welcome!
ASKER