Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7027493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:15:18+00:00 2026-05-28T00:15:18+00:00

I was able to connect to mysql db and create a table but there

  • 0

I was able to connect to mysql db and create a table but there is no data and would like to know what i am missing or doing wrong? I have post my function code below. My echo count is confirmed and I also checked my Poems.csv to ensure they are not blank.

function writeQuotestoDb() {
  $input_csv = fopen( "Poems.csv", "r" );
  $author_names = array();
  $poem_names = array();
  $poem_urls = array();

  while (($columns = fgetcsv($input_csv, 1000, ",")) !== FALSE) {
    array_push( $author_names, $columns[0] );
    array_push( $poem_names,  $columns[1] );
    array_push( $poem_urls,  $columns[2] );
  }
  fclose( $input_csv );

  $dbh = mysql_connect( 'localhost', 'root', '' );
  mysql_select_db( 'test', $dbh );
  mysql_query("CREATE TABLE  IF NOT EXISTS `poem2` (
             `id` INT( 20 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
             `author_name` varchar(128) DEFAULT NULL,
              `poem_name` varchar(128) DEFAULT NULL,
              `poem_text` text,
              `poem_url` varchar(1024) DEFAULT NULL
             ) ENGINE = MYISAM");
    mysql_query("TRUNCATE `poem2`");     
    for ( $i=0; $i<count($author_names); $i++ ) {
        $poems[$i] = substr($poems[$i],7,(strlen($poems[$i])-14));
        $poems[$i] = str_replace('"','',$poems[$i]);
        $query = 'INSERT INTO `poem2` VALUES ( NULL,"' . $author_names[$i] . '", "' . $poem_names[$i].'","' . $poem_urls[$i] .'")';
        mysql_query($query);

    }
    echo count($author_names)." rows....successfully db updated";
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:15:19+00:00Added an answer on May 28, 2026 at 12:15 am

    You are missing poem_text from your insert query. You can use the updated code below:

    function writeQuotestoDb() {
      $input_csv = fopen( "Poems.csv", "r" );
      $author_names = array();
      $poem_names = array();
      $poem_urls = array();
    
      while (($columns = fgetcsv($input_csv, 1000, ",")) !== FALSE) {
        array_push( $author_names, $columns[0] );
        array_push( $poem_names,  $columns[1] );
        array_push( $poem_urls,  $columns[2] );
        array_push( $poem_text,  $columns[3] ); // If columns[3] does not exists you can just  use array_push( $poem_text,  '' );
      }
      fclose( $input_csv );
    
      $dbh = mysql_connect( 'localhost', 'root', '' );
      mysql_select_db( 'test', $dbh );
    
      mysql_query("CREATE TABLE  IF NOT EXISTS `poem2` (
                 `id` INT( 20 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
                 `author_name` varchar(128) DEFAULT NULL,
                  `poem_name` varchar(128) DEFAULT NULL,
                  `poem_text` text,
                  `poem_url` varchar(1024) DEFAULT NULL
                 ) ENGINE = MYISAM");
        mysql_query("TRUNCATE `poem2`");     
        for ( $i=0; $i<count($author_names); $i++ ) {
            $poems[$i] = substr($poems[$i],7,(strlen($poems[$i])-14));
            $poems[$i] = str_replace('"','',$poems[$i]);
            $query = 'INSERT INTO `poem2`(`author_name`, `poem_name`, `poem_text`, `poem_url`) VALUES ( "' . $author_names[$i] . '", "' . $poem_names[$i] . '", "' . $poem_text[$i] . '","' . $poem_urls[$i] .'")';
            mysql_query($query);
    
        }
        echo count($author_names)." rows....successfully db updated";
     }
    

    If you don’t want to insert poem_text then just use the following insert statement instead of your original insert query.

     $query = 'INSERT INTO `poem2`(`author_name`, `poem_name`, `poem_url`) VALUES ( "' . $author_names[$i] . '", "' . $poem_names[$i] . '","' . $poem_urls[$i] .'")';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to be able to get html-formatted data from mysql, and turn
I have a MySQL database I'm able to connect via the command prompt and
I know questions like this have been asked numerous times, but not quite this
I need to be able to write a script to automatically connect mysql in
I'm able to connect to and read an excel file no problem. But when
I am able to connect to an Oracle database using several tools, but am
I have a VideoDisplay that is able to connect to a source and play.
I have Oracle SQL Developer already installed and am able to connect to and
I have a MySQL table named relations, as follows: from to count ------------- A
I have a MySQL table named relations, as follows: from to count ------------- A

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.