so I have this code (below) and I would like to simplify that stack of repeating lines into a single, simple loop that given and imput (say 9) incriments those values for the URL and LISTNUM. This may be really simple but I can't get my brain around it for some reason - simply because I am not sure how to deal with variables INSIDE other variable... like $_POST[$n]
if ($_POST[subby] == "subby" )
{
try {
$dbh = new PDO('mysql:host=db2asdfasdf.net;dbname=adsfasdf04', $user, $pass);
echo "Connected\n";
}
catch (Exception $e) {
die("Unable to connect: " . $e->getMessage());
}
try {
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbh->beginTransaction();
$dbh->exec("insert into vim_playlist4 (url, listnum) values ($_POST[video1], 1)");
$dbh->exec("insert into vim_playlist4 (url, listnum) values ($_POST[video2], 2)");
$dbh->exec("insert into vim_playlist4 (url, listnum) values ($_POST[video3], 3)");
$dbh->exec("insert into vim_playlist4 (url, listnum) values ($_POST[video4], 4)");
$dbh->exec("insert into vim_playlist4 (url, listnum) values ($_POST[video5], 5)");
$dbh->exec("insert into vim_playlist4 (url, listnum) values ($_POST[video6], 6)");
$dbh->exec("insert into vim_playlist4 (url, listnum) values ($_POST[video7], 7)");
$dbh->exec("insert into vim_playlist4 (url, listnum) values ($_POST[video8], 8)");
$dbh->exec("insert into vim_playlist4 (url, listnum) values ($_POST[video9], 9)");
$dbh->commit();
}
catch (Exception $e) {
$dbh->rollBack();
echo "Failed: " . $e->getMessage();
}
}
else
{}