Solved

database not getting updated

Posted on 2004-04-16
6
185 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Keep getting 503 on Curl request 6 32
php email 2 27
File submission to SQL Server 1 39
How do I make my dropdowns depended within a JQuery Modal Dialog box. 3 12
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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 …

895 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

11 Experts available now in Live!

Get 1:1 Help Now