Page 1 of 1

from text to mysql

Posted: Tue Oct 29, 2002 2:07 pm
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!

Posted: Tue Oct 29, 2002 3:02 pm
by volka

Code: Select all

mysql_query($sql, $connection) or die($sql.' :'.mysql_error);
let mysql tell its story ;)

hmm

Posted: Tue Oct 29, 2002 3:16 pm
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.

Posted: Wed Oct 30, 2002 2:08 am
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

Posted: Wed Oct 30, 2002 2:10 am
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

this is teh second post of its kind..

Posted: Wed Oct 30, 2002 5:40 pm
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?

Posted: Wed Oct 30, 2002 6:20 pm
by volka
does pba.txt contain the values already quoted?

look closely

Posted: Wed Oct 30, 2002 6:23 pm
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

Posted: Thu Oct 31, 2002 6:06 pm
by romeo
tat wa sit just FYI thanks.. I didnt get rid of all the "