Jump to content

preg_replacing


grappy

Recommended Posts

<?php$con = mysql_connect("localhost","ffs_news","123456");if (!$con) {  die('Could not connect: ' . mysql_error());}//selects databasemysql_select_db("lewke_fss", $con);//creates the query including the variables$query = "SELECT * FROM `ffs_newscontent` WHERE newscontent_sent = 0";$result = mysql_query($query);$row2 = mysql_fetch_array($result);//creates the query including the variables$query2 = "SELECT * FROM `fss_newsletter` WHERE newsletter_subscribe = 1 ";$result2 = mysql_query($query2);while ($row = (mysql_fetch_array($result2)))	{	if ($row2 <= 0)		{		}	else		{		$name = "" .$row['name']. "";		$company = "" .$row['company']. "";		$email = "" .$row['email']. "";		$string = "&name";		$string2 = "&company";		$string3 = "&email";		$to = "" .$row['newsletter_email']. "";		$subject = "" .$row2['newscontent_subject']. "";		$message = "" .$row2['newscontent_content']. "";		$headers = "From: noreply@lukegibson.co.uk";// these replacements are nessecary to create the personalised emails with names, emails and company names 		$to = preg_replace($string,$name,$to);		$to = preg_replace($string2,$company,$to);				$to = preg_replace($string3,$email,$to);		$subject = preg_replace($string,$name,$subject);		$subject = preg_replace($string2,$company,$subject);				$subject = preg_replace($string3,$email,$subject);		$message = preg_replace($string,$name,$message);		$message = preg_replace($string2,$company,$message);				$message = preg_replace($string3,$email,$message);		mail ($to, $subject, $message, $headers);		}	}//creates the query including the variables$query3 = "UPDATE `ffs_newscontent` SET newscontent_sent = 1 WHERE newscontent_sent = 0";mysql_query($query3);mysql_close($con);?>

This gives no syntax errors to run but also doesnt give the final output either, was kinda hoping if somebody here could gladly tell me where in the code ive gone wrong (Its a mail merging script)

Link to comment
Share on other sites

From what I can see, there really is no need for preg_replace here, you could just use str_replace. Preg_replace uses regix, so it requires regular expressions. If you already know what the variable you're replacing is called in your string, then there is no reason to use regex because you are only ever going to replace those strings. If you really need to use preg_replace, then at the very top of your page put this line:error_reporting(E_ALL);That'll give you any and all errors that occur inside the script. By the way, what is the layout of your databases? because i believe there might be a much simplier way to get the data from the two tables.

Link to comment
Share on other sites

From what I can see, there really is no need for preg_replace here, you could just use str_replace. Preg_replace uses regix, so it requires regular expressions. If you already know what the variable you're replacing is called in your string, then there is no reason to use regex because you are only ever going to replace those strings. If you really need to use preg_replace, then at the very top of your page put this line:error_reporting(E_ALL);That'll give you any and all errors that occur inside the script. By the way, what is the layout of your databases? because i believe there might be a much simplier way to get the data from the two tables.
hmm, well error reporting should be on all from the servers original setup but il try it...shortly after i posted this aswell i switched it all around to str_replaces instead, but to no real avail still, the layout isnt too important, this is for college so only really matters on if the thing works for now =D, il give this a try now though---Edit---After using the error_reporting(E_ALL); there was still no errors reportedpretty sure ive encountered something like this before when i accidentally left the space out of "switch($case)" when its supposed to be "switch ($case)", it gave absolutely no output not even a error, ive looked for the same error on this script so far and theres nothing to be found :s
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...