Jump to content

[SOLVED] Whats the best way?


aim25

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.