Solved

database not getting updated

Posted on 2004-04-16
6
191 Views
Last Modified: 2006-11-17
/*

Hi I have a text file called symbol1.txt I want to insert all its values in table in mysql. But the following code is not getting executed.

Please let me know why

*/


<?php
$filename = "symbol1.txt"; // File which holds all data

$arrFp = file( $filename ); // Open the data file as an array
$numLines = count( $arrFp ); // Count the elements in the array


#----------open database connection
mysql_pconnect("localhost", "amj174", "ashlee") or die("Unable to connect to SQL server");

for($i=0; $i<$numLines; $i++) // Overwrite the existing content
{
$query="INSERT INTO stocksymbol ( 'company_symbol' ) VALUES ( '$arrFp[$i]' );";

$result=mysql_query($query);
echo $result;

}

echo "successful execution";
?>
0
Comment
Question by:anshuma
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 18

Expert Comment

by:Morcalavin
ID: 10848648
Try this:

$dbh=mysql_connect ("localhost", "amj174", "ashlee") or die ('I cannot connect to the database because: ' . mysql_error());
$query="INSERT INTO stocksymbol ( 'company_symbol' ) VALUES ( '$arrFp[$i]' )";
or($i=0; $i<$numLines; $i++) // Overwrite the existing content
{
$result=mysql_query($query, $dbh);
echo $results;
}
0
 
LVL 12

Expert Comment

by:venkateshwarr
ID: 10848796
modify your query to

$query="INSERT INTO stocksymbol ( 'company_symbol' ) VALUES ( '".$arrFp[$i]."' );";
0
 

Author Comment

by:anshuma
ID: 10849563
Nothing is is working infact the query is not being executed at all. The echo result is not being run.
Here's my new code and venkat i did try your way also.


<?php


$filename = "symbol1.txt"; // File which holds all data

$arrFp = file( $filename ); // Open the data file as an array
$numLines = count( $arrFp ); // Count the elements in the array


$dbh=mysql_connect ("localhost", "amj174", "ashlee") or die ('I cannot connect to the database because: ' . mysql_error());

for($i=0; $i<$numLines; $i++) // Overwrite the existing content

{
echo $arrFp[$i]; //this statement works

//now nothing happens
$query="INSERT INTO stocksymbol ( 'company_symbol' ) VALUES ( '$arrFp[$i]' )";
$result=mysql_query($query, $dbh);
echo $result;

//and the program crashes in the above block
}




?>
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:venkateshwarr
ID: 10849733
why dont you print the query and to see if  there is anything wrong in the construction...

for($i=0; $i<$numLines; $i++) // Overwrite the existing content

{
echo $arrFp[$i]; //this statement works

//now nothing happens
$query="INSERT INTO stocksymbol ( 'company_symbol' ) VALUES ( '$arrFp[$i]' )";
print $query."<br/>";
$result=mysql_query($query, $dbh);
echo $result;

//and the program crashes in the above block
}

0
 
LVL 12

Accepted Solution

by:
venkateshwarr earned 100 total points
ID: 10849737
As far as I know,

the column names in sql query should not be enclosed in quotes..

"INSERT INTO stocksymbol (company_symbol ) VALUES ( '$arrFp[$i]' )";
0
 

Author Comment

by:anshuma
ID: 10849749
i updated it the query seems fine

visit

http://sky.smeal.psu.edu/~auj107/readsym.php

to check

amit
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question