close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

Loop Insert from an array?

Thread began 8/30/2010 9:00 am by Steve | Last modified 9/01/2010 10:16 am by Steve | 3053 views | 9 replies

Steve

Harder than I thought...

Hello,

I can't seem to get the array posted to the DA Insert Behaviour.

I can print_r the array and see the results present but in the js alert I set in the behaviour the array never shows up.

<?php require_once("../../Connections/emailList.php"); ?>
<?php require_once("../../WA_DataAssist/WA_AppBuilder_PHP.php"); ?>

<?php
// WA Application Builder Insert
if (isset($_POST["InsertMe"])) // Trigger
{


echo "<script language=\"JavaScript\">\n";
echo "alert('";
echo '<pre>';
print_r($matches[0]);
echo '</pre>';
echo "we made it this far');\n";
echo "</script>";

// loop to allow array of inserts
for($i = 0; $i < sizeof($matches[0]); $i++) {

{
$WA_connection = $emailList;
$WA_table = "phplist_user_user";
$WA_sessionName = "phplist_user_user_id";
$WA_redirectURL = "";
$WA_keepQueryString = false;
$WA_indexField = "id";
$WA_fieldNamesStr = "email|confirmed|uniqid|htmlemail|subscribepage";
$WA_fieldValuesStr = "$matches[0]" . "|" . "1" . "|" . md5(uniqid(mt_rand())) . "|" . "1" . "|" . "4";
$WA_columnTypesStr = "',none,''|none,none,NULL|',none,''|none,none,NULL|none,none,NULL";
$WA_fieldNames = explode("|", $WA_fieldNamesStr);
$WA_fieldValues = explode("|", $WA_fieldValuesStr);
$WA_columns = explode("|", $WA_columnTypesStr);
$WA_connectionDB = $database_emailList;
mysql_select_db($WA_connectionDB, $WA_connection);
if (!session_id()) session_start();
$insertParamsObj = WA_AB_generateInsertParams($WA_fieldNames, $WA_columns, $WA_fieldValues, -1);
$WA_Sql = "INSERT INTO `" . $WA_table . "` (" . $insertParamsObj->WA_tableValues . ") VALUES (" . $insertParamsObj->WA_dbValues . ")";
$MM_editCmd = mysql_query($WA_Sql, $WA_connection) or die(mysql_error());
$_SESSION[$WA_sessionName] = mysql_insert_id();
if ($WA_redirectURL != "") {
if ($WA_keepQueryString && $WA_redirectURL != "" && isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] !== "" && sizeof($_POST) > 0) {
$WA_redirectURL .= ((strpos($WA_redirectURL, '?') === false)?"?":"&").$_SERVER["QUERY_STRING"];
}
header("Location: ".$WA_redirectURL);
}
}
}
}
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Search, Find and Insert</title>
</head>

<body>


<form method="post">
Please enter full URL of the page to parse (including http://):<br />
<input type="text" name="url" size="65" value="<?php echo $the_url; ?>"/><br />
or enter text directly into textarea below:<br />
<textarea name="text" cols="50" rows="15"></textarea>
<br />
<input type="submit" value="Parse Emails" />
</form>


<p>


<form id="formUser" name="formUser" method="post" action="">
<?php
$the_url = isset($_REQUEST['url']) ? htmlspecialchars($_REQUEST['url']) : '';
?>


<?php
if (isset($_REQUEST['url']) && !empty($_REQUEST['url'])) {
// fetch data from specified url
$text = file_get_contents($_REQUEST['url']);
}
elseif (isset($_REQUEST['text']) && !empty($_REQUEST['text'])) {
// get text from text area
$text = $_REQUEST['text'];
}

// parse emails
if (!empty($text)) {
$res = preg_match_all("/[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}/i",$text,$matches);


if ($res) {
// loop through array only taking the first one of any duplicates with the array_unique function
foreach(array_unique($matches[0]) as $email) {
echo $email . "<br />";
}
}
else {
echo "No emails found.";
}
}
?>
</p>

<p>
<label for="fldEmail"></label>
Email: **
<input name="fldEmail" type="text" id="fldEmail" size="45" />
</p>
<p>&nbsp;</p>
<p>
<input type="submit" name="InsertMe" id="InsertMe" value="Submit" />
</p>
<p>&nbsp;</p>
<p>rev3</p>
</form>
<p>&nbsp;</p>
</body>
</html>



The page allows you to specify some page that has email addresses in it then using preg_match_all makes an array of the results. I now need to pass that in the insert loop to the DB.

I'm down to thinking I need pass the array in a $_POST from a hidden field but tests have not worked with that method so I am at a loss.

Any ideas?

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...