?
Solved

database not getting updated

Posted on 2004-04-16
6
Medium Priority
?
193 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 400 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

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!

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

777 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