What is wrong with using $_Request

I am trying to figure out why my php script that I should maybe use something else instead of $_Request.
Everything else on my script comes out ok. No errors or anything like that.

if (isset ($_REQUEST[‘message’]) && isset($_REQUEST[‘email’]) &&
isset($_REQUEST[‘name’]))
{
$email = $_REQUEST[‘email’];
$name = $_REQUEST[‘name’];
$subject = $_REQUEST[‘subject’];
$message = $_REQUEST[‘message’];
if (strlen($message) > 0 && strlen($email) > 0 && strlen($subject) > 0 && strlen($name) > 0)
{ $sendMessage = true;}
}

if (isset ($_REQUEST[‘posted’]) && (!$sendMessage))
{ echo “Please fill in all the values”;}

Hello,

If you know that the information is being sent via the post method, use $_POST. If you know the information is being sent via the get method, use $_GET. $_REQUEST is an associative array that, by default, contains the contents of $_GET, $_POST and $_COOKIE. You would use $_REQUEST if you are dealing with a combination of $_POST, $_GET, and $_COOKIE arrays. However while it is somewhat convenient, you probably would want to use either $_POST, $_GET, $_COOKIE, etc separately. If your scripts are using $_POST, use $_POST and the same with GET; that’s what is used by most.

Cheers!

Ok. Thank you for your help. I will go ahead and switch the $_Request to $_POST because I am trying to have my contact form on my site work properly. Once I hit submit then it just goes to a pure blank page. No error on the page or anything. Nothing else is showing on my script except those. I am using a contact.html and I have my php script that I am working on. My contact html is under my end php tag also.

What is suppose to go in replace of $_Request? I tried using $_POST and $_GET and they didn’t work out either. I didn’t use POST or GET in every single one. I mixed it up to. Not sure why my Editor is saying it is wrong. Am I suppose to have another bracket or something in that area??

Jogden614,

If you know exactly what the key values are when you send and come to this page (i.e. $_POST[‘foo’] and $_GET[‘bar’]) and the values are not the same as in the other, you can transform them into local variables by using the following (please note that if you have a variable in $_POST that’s the same in $_GET, it will be overwritten):

[php]foreach($_POST as $key => $value) {
$$key = htmlspecialchars($value);
}

foreach($_GET as $key => $value) {
$$key = htmlspecialchars($value);
}[/php]

What this does is take (for example) $_POST[‘foo’] which equals ‘bar’ and creates a variable called $foo and assigns the value ‘bar’ in it. This is a short way of creating a local variable and assigning it the value that was giving from the $_POST and $_GET. Try it out and tell me if this solves your problem.

Cheers!

Ok. Would I put that after the
$name
$email
$subject
$message
?

Or would I put it after the 1st

if (isset

I am pretty sure that it doesn’t matter, but I am going to change it all to $_POST in the mean time and see if you write back. If not I am going to put it after the first if (isset

Thank you for your help also

I went ahead and added the attachment that I am working on, so that way you have a better understanding of what is going on with it all.


mailer.zip (1.55 KB)

Jogden614,

Keep in mind that when you use:

[php]foreach($_POST as $key => $value) {
$$key = htmlspecialchars($value);
}[/php]

You no longer have to use:

[php]$foo = $_POST[‘foo’][/php]

The FOREACH statement does that to all of the key pairs in the $_POST. What is exactly wrong now? Everything looks okay on my end syntactically.

Cheers!

Right. I know that when using foreach it states for each $_POST in the script, but for some reason my end it is saying to use filtering instead. Why? I have no idea. It is saying to use some filtering functions instead. That is for the $_POST. I am going to go ahead and try it even though that is popping up because I believe that it is okay.

I am getting frustrated. I don’t get why it is being crazy. Now since I did the $_POST, it isn’t going to the blank page. It is just acting like it is reloading. It refreshes the page and makes the text box bigger. I went ahead and added another zip file. It has my php and my contact html. I also have a thanks.html that people could go to, but I just want to get this figured out and worry about the thanks later.


mailer.zip (2.56 KB)

I rename contactus.html to contactus.php

[php]<?php session_start(); ?>
<!doctype html>

Contact Us Top Notch Web Creations TN <?= isset($_SESSION['error']) ? $_SESSION['error'] : 'Contact Us'; ?>

If you would like to contact me or give me feedback please use the form below. I check my emails very often and I will get back to you as soon as I can. I usually reply back to the email no later than 48 hours. If it does happen then it is becuase their is a high volume of emails coming in at the time, but you should recieve an email within 2 days after. If you would like a quicker response, please email me at [email protected].

	<p class="info">
		<label for="name">Name</label>
		<input type="text" name="name" placeholder="Full Name"/>
	</p>
	<p class="info">
		<label for="Email">Email</label>
		<input type="text" name="email" placeholder="Email"/>
	</p>
	<p class="info">
		<label for="Site">Website</label>
		<input type="text" name="site" placeholder="Website"/>
	</p>
	<p class="info">
		<label for="subject">Subject</label>
		<input type="text" name="subject" placeholder="Subject"/>
	</p>
	<p class="message" id="box">
		<textarea name="message" placeholder="Message" rows="15" cols="40" /></textarea>
	</p>
	<p class="submit">
		<input type="submit" name="submit" value="Send"/>
	</p>
</form>
Copyright ©2014 TopNotchWebCreations, All Rights Reserved [/php]

and left mailer.php name the same:
[php]<?php
session_start();
$sendMessage = true;

if ( isset($_POST[‘submit’]) && $_POST[‘submit’] == ‘Send’)
{
$email = $_POST[‘email’];
$name = $_POST[‘name’];
$subject = $_POST[‘subject’];
$message = $_POST[‘message’];

if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
	$sendMessage = false;
	$_SESSION['error'] = 'Invalid Email, Please Re-Enter';
} 

if ( empty($name) || empty($subject) || empty($message) ) {
	$sendMessage = false;
	$_SESSION['error'] = 'Fields Can\'t Be Blank, Please Re-Enter';
}

if ( $sendMessage ) { 
	
	$to= "[email protected]";
	$subject= "Website Feedback.";
	$headers= "Mime Version: 1.0". "\r\n";
	$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
	$headers .= "From: $email\r\n";       // setup the from field for e-mail
	$headers .= "Content-type: text/html\r\n";      // setup e-mail format
	
	$success = mail($to, $subject, $message, $headers);
} else {
	
	
	header('Location: contactus.php');
	exit();
}

}[/php]

However, sending mail I have no idea if that works or not, but if it doesn’t I’m sure someone will help you.

Thanks for the reply. I tried that and it didn’t work. It wouldn’t let me upload my page when I did contactus.php. I added the HTML and the PHP version of it and it didn’t work. I really don’t know where I am going wrong with it all.

What exactly are you trying to do? Upload a page? I thought this was sending an email message, everything works until the actual send email portion.

Yes sir. I am trying to have my viewers/customers send me an email through my contact page. Once they fill out the form then they can hit submit and an email gets sent to my email. As of right now it isn’t sending the email. Once I get the email figured out and it is getting sent successfully then I am going to have a thank you part and letting the customer know that it is sent successfully.

Sponsor our Newsletter | Privacy Policy | Terms of Service