Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 10th, 2010, 01:42 PM
Registered User
 
Join Date: Feb 2010
Location: Brandon, Manitoba, Canada
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy Need help inserting to a database then emailing

I need help inserting to a database then emailing that information. I am running into a PHP Notice: Undefined variable: REQUEST_METHOD on line 20 error also. It will not post to the database. It is on CentOS 5.4, with PHP 5.2.11, MySQL 5.0.86 and Apache 2.2.14.

Here is the script so far:

<?php

$usr = "dbuser"; #not real
$pwd = "dbpassword"; #not real
$db = "dbcontacts";
$host = "localhost";

// connect to database
$cid = mysql_connect($host,$usr,$pwd);
if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); }

?>
<?php
// this is processed when the form is submitted
// back on to this page (POST METHOD)
if ($REQUEST_METHOD=="POST") {

// double-up apostrophes
$email = $_POST['email'];
$ip = gethostbyname($_SERVER['REMOTE_ADDR']);


// setup SQL statement
$SQL = " INSERT INTO contacts ";
$SQL = $SQL . " (email, date, ip) VALUES ";
$SQL = $SQL . " ('$email', NOW(), '$ip') ";

//execute SQL statement
$result = mysql_db_query($db,"$SQL",$cid);

// check for error
if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); }

if($result)
{
//send the email

$to = "email@domain.com"; #not real
$subject = "New contact from the website";

//headers and subject
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: <".$email.">\r\n";

$body = "New contact<br />";
$body .= "Email: ".$email."<br />";
$body .= "IP: ".$ip."<br />";

mail($to, $subject, $body, $headers);

//ok message

echo "Your message has been sent";
}

}

?>
<div id="wrap"> <img src="http://p2p.wrox.com/images/top.jpg" id="top">
<div id="piece3">
<form method=post action="index.php" >
<input type=hidden name=redirect value="thankyou.php" />
<input type=hidden name=errorredirect value="error.php" />
<script type="text/javascript">
function verifyRequired() {
if (document.icpsignup["fields_email"].value == "") {
document.icpsignup["fields_email"].focus();
alert("The Email field is required.");
return false;
}
return true;
}
</script>
<input type=text name="email" id="email" title="Enter your email address">
<input name="Submit" type="submit" id="subscribe" value="" />

</form>
</div>
<div id="alerts">
<ul class="hoverbox">
<li><a href="#"><img src="http://p2p.wrox.com/images/Stock1.jpg"><img src="http://p2p.wrox.com/images/vnda.png" class="preview"></a></li>
</ul>
<ul class="hoverbox2">
<li><a href="#"><img src="http://p2p.wrox.com/images/Stock2.jpg"><img src="http://p2p.wrox.com/images/pir.png" class="preview"></a></li>
</ul>
<ul class="hoverbox3">
<li><a href="#"><img src="http://p2p.wrox.com/images/Stock3.jpg"><img src="http://p2p.wrox.com/images/gvbp.png" class="preview"></a></li>
</ul>
<ul class="hoverbox4">
<li><a href="#"><img src="http://p2p.wrox.com/images/Stock4.jpg"><img src="http://p2p.wrox.com/images/fre.png" class="preview"></a></li>
</ul>
</div>
<div id="footer">
<h1>Grow your portfolio like you never have, subscribe free above</h1>
</div>
</div>
<?php
mysql_close($cid);
?>


Can anybody help?

Last edited by gueland; February 10th, 2010 at 01:45 PM.. Reason: missed information
Reply With Quote
  #2 (permalink)  
Old March 19th, 2010, 04:15 PM
Friend of Wrox
 
Join Date: Dec 2008
Location: , , .
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default

Instead of using $REQUEST_METHOD, use $_SERVER['REQUEST_METHOD'].
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help in inserting to Database?? Hannibal Pro JSP 0 March 14th, 2006 07:11 AM
inserting into database shieldsteven VS.NET 2002/2003 0 November 11th, 2004 07:44 PM
inserting into database shieldsteven VS.NET 2002/2003 8 October 20th, 2004 05:33 PM
Emailing File from SQL Server Database hugh@kmcnetwork.com VB How-To 0 July 24th, 2004 09:06 AM
Inserting into database ZiqXx C# 6 July 5th, 2004 04:13 AM



All times are GMT -4. The time now is 02:20 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.