abhikerl Posted September 22, 2009 Share Posted September 22, 2009 hi, can anyone explain me how to insert data in the database using arrays. I know only how to insert using post method. I am learning OOP in php. thanks Link to comment https://forums.phpfreaks.com/topic/175095-insert-in-database-using-array/ Share on other sites More sharing options...
trq Posted September 22, 2009 Share Posted September 22, 2009 Pretty vague question really. $a = array('bob','marry','jane'); foreach ($a as $v) { $sql = "INSERT INTO users (name) VALUES ('$v')"; mysql_query($sql); } Link to comment https://forums.phpfreaks.com/topic/175095-insert-in-database-using-array/#findComment-922845 Share on other sites More sharing options...
abhikerl Posted September 22, 2009 Author Share Posted September 22, 2009 Thanks for the answer but I wasn't clear enough. Actually, suppose I have a form with data which I want to insert in the database. We will use : "mysql_query("INSERT INTO Persons (FirstName, LastName, Age) VALUES ('Peter', 'Griffin', '35')");" But I want to use array to insert this type of data.. Link to comment https://forums.phpfreaks.com/topic/175095-insert-in-database-using-array/#findComment-922850 Share on other sites More sharing options...
trq Posted September 22, 2009 Share Posted September 22, 2009 Still not clear enough. What does the array look like? Link to comment https://forums.phpfreaks.com/topic/175095-insert-in-database-using-array/#findComment-922852 Share on other sites More sharing options...
PFMaBiSmAd Posted September 22, 2009 Share Posted September 22, 2009 Slightly off topic, but a person's age is not a constant unless they are dead. You should store the date of birth instead of their age. Use a DATE data type YYYY-MM-DD. Link to comment https://forums.phpfreaks.com/topic/175095-insert-in-database-using-array/#findComment-922858 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.