from text to mysql

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
romeo
Forum Contributor
Posts: 138
Joined: Sun Apr 21, 2002 12:50 pm

from text to mysql

Post by romeo »

Code: Select all

<?

/*db variables*/
$db_name = "xxx";
$table_name = "xxx";
$server_name = "localhost";
$user_name = "xxx";
$password = "xxx";

$connection = @mysql_connect($server_name, $user_name, $password) or die("could not connect");
$db = mysql_select_db($db_name, $connection) or die ("could not create connection");



/*text variables*/
$filename = "pba.txt";
$file=file($filename);
while(list(,$value)=each($file))
&#123;
list($First_Name,$Last_Name,$Company,$Address,$City,$State,$Zip_Code,$Active,$Work_Phone,$Fax_Phone,$Email,$Member_Class,$Type)=split( "\,", $value);

$First_Name = ucwords(strtolower($First_Name));
$Last_Name = ucwords(strtolower($Last_Name));
$Company = ucwords(strtolower($Company));
$Address = ucwords(strtolower($Address));
$City = ucwords(strtolower($City));
$State = ucwords(strtolower($State));
$Zip_Code = ucwords(strtolower($Zip_Code));
$Active = ucwords(strtolower($Active));
$Work_Phone = ucwords(strtolower($Work_Phone));
$Home_Phone = ucwords(strtolower($Home_Phone));
$Fax_Phone = ucwords(strtolower($Fax_Phone));
$Email = trim(strtolower($Email));
$Type = ucwords(strtolower($Type));



/*inserting text into database*/
$sql = "INSERT INTO $table_name (First_Name, Last_Name, Company, Address, City, State, Zip_Code, Active, Work_Phone, Fax_Phone, Email, Member_Class, Type)
VALUES ("$First_Name", "$Last_Name", "$Company", "$Address", "$City", "$State", "$Zip_Code", "$Active", "$Work_Phone", "$Fax_Phone", "$Email", "$Member_Class", "$Type")";

mysql_query($sql, $connection) or die("could not execute query");


&#125;
?>
Getting a "could not execute" ...

at first i posted in Db because of it dealing with Mysql but realized it's technically a php command that may be buggin me...

Any helpis appreciated!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

mysql_query($sql, $connection) or die($sql.' :'.mysql_error);
let mysql tell its story ;)
romeo
Forum Contributor
Posts: 138
Joined: Sun Apr 21, 2002 12:50 pm

hmm

Post by romeo »

INSERT INTO memberdirectory (First_Name, Last_Name, Company, Address, City, State, Zip_Code, Active, Work_Phone, Fax_Phone, Email, Member_Class, Type) VALUES (""bob"", ""xxx"", ""#1xxx"", ""xxx William Penn Hwy"", ""xxx"", ""pa"", ""15146"", ""active"", ""xxx-xxx-xxxx"", ""xxx-xxx-8906"", """", ""B"", ""sales" ") :mysql_error


something is telling me this is no what you want.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Please do not make multiple posts on the same question or cross-post - this is the third one so far. Post once and if you feel you've posted in the wrong place don't post again, put a note in the original that you feel it should be moved and one of the mod's or admins will take it from there.

Mac
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

volka wrote:

Code: Select all

mysql_query($sql, $connection) or die($sql.' :'.mysql_error);
You need to change mysql_error to mysql_error()

I'm moving this back to the database forum 'cause it really belongs there.

Mac
romeo
Forum Contributor
Posts: 138
Joined: Sun Apr 21, 2002 12:50 pm

this is teh second post of its kind..

Post by romeo »

but thanks for pointing out the ()

so i get this werror

You have an error in your SQL syntax near 'bob"", ""corbin"", ""#1 Cochran"", ""4200 William Penn Hwy"", ""monroeville"", "' at line 2

somethig to do with the quotes?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

does pba.txt contain the values already quoted?
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

look closely

Post by phpScott »

8O your double quotes are quoting nothing, meanwhile your values are sitting in no-mans-land.
Try not back slashing your quotes as this is causing them to be displayed in the query and they don't have to be.

phpScott
romeo
Forum Contributor
Posts: 138
Joined: Sun Apr 21, 2002 12:50 pm

Post by romeo »

tat wa sit just FYI thanks.. I didnt get rid of all the "
Post Reply