Solved

database not getting updated

Posted on 2004-04-16
6
190 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

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…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

737 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