Solved

database not getting updated

Posted on 2004-04-16
6
180 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
  • 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …

762 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now