PHP Help moving code from HTML site to Wordpress

Hi

I’m currently in the process of re-developing a website for a client in Wordpress. I’ve completed the work apart from the fact that on the old site the client has a webpage with an email subscription form for subscribing to a newsletter. The form takes a ‘Name’ and ‘Email Address’ and writes these to a MySQL database in the back end.

I’ve tried adding the code to a page in wordpress and have a few plugins which allow PHP code execution on both the sidebar and page but when the button is clicked to submit the subscription nothing appears to happen as on the origonal page.

I really need to know whether this type of code could be imported into Wordpress and made to work or how to go about writing a wordpress page that will write to the same database.

Any advice on this would be helpful as I’m not a strong php coder.

The Code is as follows:

There’s a contact.php page on the origoanl site that calls inc-mailing-list.php that also referrences a mysqlconnections.php file

I’ve put all the code below for referrence.

Origonal Site: contact.php
Code: <?php
session_start();
$string = strtoupper($_SESSION[‘string’]);
$userstring = strtoupper($_POST[‘userstring’]);
session_destroy();

?>

HTML FORMATTING REMOVED

<?php include("inc-mailing-list.php"); ?>

INC-MAILING-LIST.PHP

<?php require_once('Connections/mysqlconnection.php'); ?> <?php /* In contact.php session_start(); $string = strtoupper($_SESSION['string']); $userstring = strtoupper($_POST['userstring']); session_destroy(); */ ///// Anti sql injection if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } //// Site config $siteName = "South Wales Art Society"; $siteURL = "www.southwalesartsociety.co.uk"; $siteEmail = "[email protected]"; ///// Establish the current date/time as a variable $now = date('Y-m-d H:i:s'); // Current date //// Call mailing lists mysql_select_db($database_mysqlconnection, $mysqlconnection); $query_callMailingLists = "SELECT * FROM content WHERE contenttype = 501 AND onlinestatus = '1' ORDER BY displayorder ASC"; $callMailingLists = mysql_query($query_callMailingLists, $mysqlconnection) or die(mysql_error()); $row_callMailingLists = mysql_fetch_assoc($callMailingLists); $totalRows_callMailingLists = mysql_num_rows($callMailingLists); //// Unsubscribe if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "elist") && ($_POST["subscription"] == "unsubscribe") && (strlen($_POST["email"]) > 4) && ($string == $userstring) && (strlen($string) > 4)) { $deleteSQL = sprintf("DELETE FROM content WHERE email=%s AND contenttype = 500", GetSQLValueString($_POST['email'], "text")); mysql_select_db($database_mysqlconnection, $mysqlconnection); $Result1 = mysql_query($deleteSQL, $mysqlconnection) or die(mysql_error()); $status = "1"; //SEND CONFIRMATION EMAIL $to = $_POST['email']; $subject = $siteName.' Mailing List'; $body = 'Your email address has been removed from the '.$siteName.' mailing list.' . "\n\r"; $body .= $siteURL . "\n\r"; $headers = 'From: '.$siteEmail . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $body, $headers); } /////////////////// SUBSCRIPTION //////////////////////// // Insert comment if sent and valid if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "elist") && ($_POST["email"] != "") && ($_POST["subscription"] == "subscribe") && ($string == $userstring) && (strlen($string) > 4)) { //////////////////////////////////////////////////////////////////////////////////// ///////////////////////////// COUNT AND JOIN TAGS ////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////// $tagCombination1 = ""; // Default value to define variable. $tagTotal = ""; // Default value to define variable. if (isset($_POST['TagsTotal1'])) { $tagTotal = $_POST['TagsTotal1'];} $tagNumber = 0; do { $tagNumber = $tagNumber+1; if (isset($_POST['Tag-1-'.$tagNumber])) $tagCombination1 = $tagCombination1.",".$_POST['Tag-1-'.$tagNumber]; // DISREGARD UNSELECTED TAGS } while ($tagNumber <= $tagTotal); // LOOP UNTIL ALL TAGS HAVE BEEN COMBINED $tagCombination1 = $tagCombination1.","; // ADD A COMMA TO THE END TO GET CORRECT SEARCH PARAMETERS $tagCombination1 = str_replace(",,",",",$tagCombination1); // CLEAR OUT ANY DOUBLE COMMAS //////////////////////////////////////////////////////////////////////////////////// /////////////////////////// COUNT AND JOIN TAGS END //////////////////////////////// //////////////////////////////////////////////////////////////////////////////////// $insertSQL = sprintf("INSERT INTO content (contenttype, title1, email, date_added, tags1) VALUES (%s, %s, %s, %s, %s)", GetSQLValueString(500, "int"), GetSQLValueString($_POST['name'], "text"), GetSQLValueString($_POST['email'], "text"), GetSQLValueString($now, "text"), GetSQLValueString($tagCombination1, "text")); mysql_select_db($database_mysqlconnection, $mysqlconnection); $Result1 = mysql_query($insertSQL, $mysqlconnection) or die(mysql_error()); $status = "2"; //SEND CONFIRMATION EMAIL $to = $_POST['email']; $subject = $siteName.' Mailing List'; $body = 'Thank you. Your name has been added to the '.$siteName.' mailing list.' . "\n\r"; $body .= $siteURL . "\n\r"; $headers = 'From: '.$siteEmail . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $body, $headers); } ?>
Sign Up For Our Mailing List
<?php if (($_POST['email']) && ($status == "1")) { ?>


Thank you, you have been removed from the mailing list.

<?php } elseif (($_POST['email']) && ($status == "2")) { ?>


Thank you, you have been added to the mailing list.

<?php } else { ?> <?php if (($_POST['email']) && ($status != "2")) { ?>

Please complete your details and enter the code.

<?php } // Error ?>

Name:

Email:

<input name=“subscription” type=“radio” id=“subscription_0” value=“subscribe” <?php if($_GET['unsubscribe']!="yes") { ?>checked=“checked”<?php } // ?> />
Subscribe

<input type=“radio” name=“subscription” value=“unsubscribe” id=“subscription_1” <?php if($_GET['unsubscribe']=="yes") { ?>checked=“checked”<?php } // ?>/>
Unsubscribe


<?php /*?>Select which information you would like to receive:
<?php $tagNumbers = 0; do { $tagNumbers = $tagNumbers+1;?>

<input <?php if (!(strcmp($row_callMailingLists['id'],1000))) {echo "checked=\"checked\"";} ?> name=“Tag-1-<?php echo $tagNumbers; ?>” type=“checkbox” value="<?php echo $row_callMailingLists['id']; ?>" /><?php echo $row_callMailingLists['title1']; ?>

<?php } while ($row_callMailingLists = mysql_fetch_assoc($callMailingLists)); ?>

USE THE TWO HIDDEN FIELDS BELOW AS THERE IS ONLY ONE LIST

<?php */?>



Please enter the code shown above.




<?php } // ?> <?php mysql_free_result($callMailingLists); ?>
Sponsor our Newsletter | Privacy Policy | Terms of Service