aim25 Posted June 26, 2007 Share Posted June 26, 2007 Okay, i'm making a sign up page. When you are signing up you get the option of choosing which newsletters you would like to receive. I put the information in an array called news: <?php //array broken down $news[0] = $_POST['weekly']; $news[1] = $_POST['news1']; $news[2] = $_POST['news2']; $news[3] = $_POST['news3']; $news[4] = $_POST['news4']; $news[5] = $_POST['news5']; $news[6] = $_POST['news6']; $news[7] = $_POST['news7']; $news[8] = $_POST['news8']; $news[9] = $_POST['news9']; ?> So now i'm going to store this information into my db: <?php //this is the main part if(!empty($news[0])) { mysql_query("INSERT INTO members(news1) VALUES ('1');"); } // and then ill repeat the code above for each news letter, editing the values ofcourse ?> But the problem is that this may get lengthy, so i'm looking for a better way to do this. Note: on the html page the the input fields for the newsletters are checkboxes Quote Link to comment Share on other sites More sharing options...
soycharliente Posted June 26, 2007 Share Posted June 26, 2007 Write a function that takes in the array entry as the param and use the param as the variable that's put into the db. Quote Link to comment Share on other sites More sharing options...
aim25 Posted June 26, 2007 Author Share Posted June 26, 2007 Thats geat advice, if i knew what u were talking about. Quote Link to comment Share on other sites More sharing options...
soycharliente Posted June 26, 2007 Share Posted June 26, 2007 Write a for loop that loops through each element of your array and tests for empty. If it's not empty, grab what's inside a run a function on it. setUserNewsLetter($arrayElement) { $qry="UPDATE news SET newslettertosend='$arrayElement'"; } Something like that. IDK how your db is structured or if they can pick more than one newsletter or anything so there could be mroe to it. Quote Link to comment Share on other sites More sharing options...
aim25 Posted June 26, 2007 Author Share Posted June 26, 2007 Thanks, that works!!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.