Adding Data from an Array into a MySQL DB
Posted: Thu Jul 09, 2009 11:09 am
Hi guys,
As you can see from my code iam attemping to add data from an array that goes up to 20 possiable fileds, some maybe empty, and in the tests iam runing i only use 3 fields. But its not working, even when i select $SQL2 which only has the three fileds seleted, it still will not add the test data to the DB.
All i get back from my if statement is 'Error'.......
I have not worked with MySQL in some years and I think there is something iam doing wrong - there must be or it would be working
- but i can not see what it is, please help?
This is how iam connecting to my database, this is held within another file and i use require_once to access it - this works even when i want to access the database to print information from it, which i can do, just not add data to it!
Thanks Glenn
As you can see from my code iam attemping to add data from an array that goes up to 20 possiable fileds, some maybe empty, and in the tests iam runing i only use 3 fields. But its not working, even when i select $SQL2 which only has the three fileds seleted, it still will not add the test data to the DB.
All i get back from my if statement is 'Error'.......
I have not worked with MySQL in some years and I think there is something iam doing wrong - there must be or it would be working
Code: Select all
$SQL1 = "INSERT INTO Billing (Item01, Item02, Item03, Item04, Item05, Item06, Item07, Item08, Item09, Item10, Item11, Item12, Item13, Item14, Item15, Item16, Item17, Item18, Item19, Item20) VALUES ($Form_In[1], $Form_In[2], $Form_In[3], $Form_In[4], $Form_In[5], $Form_In[6], $Form_In[7], $Form_In[8], $Form_In[9], $Form_In[10], $Form_In[11], $Form_In[12], $Form_In[13], $Form_In[14], $Form_In[15], $Form_In[16], $Form_In[17], $Form_In[18], $Form_In[19], $Form_In[20] )";
$SQL2 = "INSERT INTO Billing (Item01, Item02, Item03) VALUES ('test1', 'test2', 'test3')";
$SQLRun = mysql_query($DB_Link, $SQL2);
if (mysql_affected_rows($DB_Link) == 1) {
print ("your db data has been added");
} else {
print ("Error");
}
This is how iam connecting to my database, this is held within another file and i use require_once to access it - this works even when i want to access the database to print information from it, which i can do, just not add data to it!
Thanks Glenn
Code: Select all
<?php
$Host = "localhost";
$User = "USER";
$Pass = "PASSWORD";
$DB_Name = "DB_NAME";
$DB_Link = mysql_pconnect($Host, $User, $Pass);
mysql_select_db($DB_Name, $DB_Link);
?>