0

i'm writing a script to throttle some of the domains i send my newsletter to. I've had issues with getting emails blocked in the past.

All I'm doing is storing the throttling information into the database so my mail script will know which rate to send. Sometimes I'll have lists of 100 or so different destination domains i want to throttle, so to be able to load them all into one box and set the rate will be very convenient for me.

everything works, even the query, but I'm completely lost on getting each line inside the db as it's own record.

here is my html which works fine:

<form method="post" action="throttle_engine.php">
<textarea name="bulk" rows="7" cols="20"></textarea>
<input type="text" name="interval" value="">
<input type="submit" name="submit">
</form>

php on submission page to pass variables:

$bulk = nl2br($_POST['bulk']);
$interval = $_POST['interval'];

processing page 'throttle_engine.php':

foreach($bulk as $key=>$value){
    $query = "INSERT INTO `node".$node_id."` (domain, speed) VALUES ('$bulk', '$interval') ON   DUPLICATE KEY UPDATE `speed` = '$interval'";
    $result = mysql_query($query) or die(mysql_error());
    }


i know the query itself is working just fine, but very confused on how to add the records one line at a time in a loop. any ideas, tips, hints, or tricks are very welcome!

1 Answer 1

1

You need to break up bulk by newlines (or <br> since you've converted them)

$bulk = explode("<br>", $bulk);
foreach($bulk as $domain){
    //stuff ...
}

By making an array of domains, you can add multiple records into the database, based on each domain you've entered (assuming they are separated by a newline)

Sign up to request clarification or add additional context in comments.

1 Comment

got it working thanks! gonna save that little snippet for sure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.