Jump to content

T_String Error...Posting my code...please explain why this isn't working


inquisitive

Recommended Posts

<?php
// Pick up the form data and assign it to variables
$name= $_Post['name'];
$email= $_Post['email'];
$topic= $_Post['topic'];
$comments= $_Post['comments'];

//Build the email (replace the address is the $to section  with your own)
$to = 'provost.design@gmail.com';
$subject = "New Message: $topic";
$message = "$name said: $comments";
$headers = "From: $email";

//Send the mail using PHPs mail ()  Function
mail($to, $subject, $message, $headers);

//Redirect
header("location: success.html");

$sql = CREATE TABLE submissions(
name VARCHAR(100) NOT NULL,
email VARCHAR(255) NOT NULL,
topic VARCHAR(255) NOT NULL,
comments TEXT NOT NULL
);
mysql_query( $sql, $conn );

//Open database connection
$conn = mysql_connect('localhost', 'hp_admin', 'portable');
mysql_select_db('contact');

//Insert data
$query = "INSERT INTO submissions (name, email, topic, comments)
VALUES ('$name', '$email', '$topic', '$comments',)";
mysql_query($query);

//close connection
mysql_close($conn);

//Ioen database connection
$conn = mysql_connect('localhost','hp_admin','portable');

//Data cleaning function
function clean_data($string) {
if (get_magic_quotes_gpc() ) {
$string = stripslashes($string);
}
return mysql_real_escape_string($string);
}

//Pick up the cleaned for data
$name= clean_data($_Post['name']);
$email= clean data($_Post['email']);
$topic= clean_data($_Post['topic']);
$comments= clean_data($_Post['comments']);

//Data cleaning function
function clean_data($string) {
if (get_magic_quotes_gpc()) {
$string = stripslashes($string);
}
$string = strip_tags($string);
return mysql_real_escape_string($string);
}

//Mail header removal
function remove_header($string) {
$headers = array(
	"/to\:/i",
	"/from\:/i",
	"/bcc\:/i",
	"/cc\:/i",
	"/Content\-Transfer\-Encoding\:/i",
	"/Content\-Type\:/i",
	"/Mime\-Version\:/i"
);
retufn preg_replace($headers, '', $string);
}

function remove_headers($string) {
$headers = array(
		"/to\:/i",
	"/from\:/i",
	"/bcc\:/i",
	"/cc\:/i",
	"/Content\-Transfer\-Encoding\:/i",
	"/Content\-Type\:/i",
	"/Mime\-Version\:/i"
);
if (preg_replace($headers, '', $string) == $string) {
return $string;
} else {
die('You think Im spammy? Spammy how? Spammy like a clown, spammy?');
}
}

//Mail header removal
function remove_headers($string) {
$headers == array(
	"/to\:/i",
	"/from\:/i",
	"/bcc\:/i",
	"/cc\:/i",
	"/Content\-Transfer\-Encoding\:/i",
	"/Content\-Type\:/i",
	"/Mime\-Version\:/i"
);
$string = preg_replace($headers, '',string);
return strip_tags($string);
}

//Pick up the cleaned form data
$name= remove_headers($_Post['name']);
$email= remove_headers($_Post['email']);
$topic= remove_headers($_Post['topic']);
$comments= remove_headers($_Post['comments']);

Link to comment
Share on other sites

2 errors I caught...

 

retufn preg_replace($headers, '', $string);

 

needs to be 'return'

 

$query = "INSERT INTO submissions (name, email, topic, comments)
   VALUES ('$name', '$email', '$topic', '$comments',)";

 

remove the very last comma after the $comments' just before the closing parenthesis

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.