Jump to content

Moving PHP code from HTML site to wordpress


bvrussell

Recommended Posts

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 PAGE FORMATTING (REMOVED FOR THE POST)

 

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

<script type="text/javascript">

var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");

document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

</script>

<script type="text/javascript">

try {

var pageTracker = _gat._getTracker("UA-9716450-1");

pageTracker._trackPageview();

} catch(err) {}</script></body>

 

</html>

 

 

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 = "info@southwalesartsociety.co.uk";

 

///// 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);

 

 

 

}

?>

 

<div id="signup" >

<H5>Sign Up For Our Mailing List</H5>

 

<?php if (($_POST['email']) && ($status == "1")) { ?>

<br /><strong>Thank you, you have been removed from the mailing list.</strong>

 

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

<br /><strong>Thank you, you have been added to the mailing list.</strong>

 

<?php } else { ?>

 

 

<form name="elist" method="POST" action="">

<?php if (($_POST['email']) && ($status != "2")) { ?><p class="red"><strong>Please complete your details and enter the code.</strong></p><?php } // Error ?>

 

<br />

 

Name: <input name="name" type="text" value="<?php echo $_POST['name']; ?>" /><br />

Email: <input name="email" type="text" value="<?php echo $_POST['email']; ?>" /><br />

 

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

Subscribe<br />

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

Unsubscribe<br />

 

<br />

 

<?php /*?>Select which information you would like to receive:<br />

   

<?php $tagNumbers = 0; do { $tagNumbers = $tagNumbers+1;?>

<label><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']; ?></label><br />

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

 

<input type="hidden" name="TagsTotal1" value="<?php echo $totalRows_callMailingLists; ?>" />

 

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

 

<?php */?>

<input type="hidden" name="Tag-1-1" value="1000" />

<input type="hidden" name="TagsTotal1" value="1" />

 

<img src="/captcha/imagebuilder.php" alt="" border="0" /><br /><br />

 

<small>Please enter the code shown above.</small><br />

 

<input maxlength="8" size="8" name="userstring" type="password" value="" /><br /><br />

 

<input name="Submit" type="submit" value="Submit" /><br />

 

 

<input type="hidden" name="datesubscribed" value="<?php echo date('Y-m-d H:i:s'); ?>" />

<input type="hidden" name="MM_insert" value="elist" />

</form>

</div>

<?php } // ?>

<?php

mysql_free_result($callMailingLists);

?>

 

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.