私はこのフォームを作成:このPHPコード付きPHP/HTML形式のメールフォームもはやMySQLデータベースに提出
<form method="post" action="process-form.php" id="emailForm" name="emailForm" target="_self">
<h4>Sign up to be notified when we go live!</h4>
<label for="email">E-mail</label>
<input type="text" name="email" id="email" />
<input type="submit" name="submit" id="submit" value="Submit" onclick="return alert('Thanks! Your email has been added.');">
<p>emails will not be shared with third parties</p>
</form>
<?php
//open database connect
$username = "username";
$password = "password";
$hostname = "server";
$conn = mysql_connect($hostname, $username, $password);
if (!$conn) die('Could not connect: ' . mysql_error());
//emaillist is the name of the database
mysql_select_db('emaillist');
//Clean data
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_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 cleaned data
$email = clean_data($_POST['email']);
//Insert data
//emails is the name of the table
$query ="INSERT INTO emails (email)
VALUES ('$email')";
mysql_query($query);
//close Connection
mysql_close($conn);
//redirect to page
header('Location: defaultUpCyc.html');
?>
すべては私のテスト環境で結構な作業とためました私はそれを生きて置く数日。しかし、私は自分のデータベースに行き、電子メールが送信されたかどうかを確認しました。私はテスト電子メールをフォームに入れ、dbをチェックして何もない。私はそれを生きているので、私は何も変えていない。ここにテストサイトがあります:http://upcycledonline.com/test/Site/defaultUpCyc.html
ありがとうございます!
を使用することができますあなたのコードは、何らかのエラー報告をまったく行っていないか、イベントが成功したかどうかをチェックしています。たとえば、mysql_connectはデータベースハンドルを返します。データベースに接続できなかった場合はfalseを返します。 mysql_connectが有効なdbハンドルを返したかどうかをチェックしていないので、スクリプトはデータベースへの接続に失敗したかどうかを知るはずです。コードには、操作が成功したかどうかをチェックしていない点がいくつでもありますが、それらの点のいずれかでスクリプトが失敗している可能性があります。 – GordonM
私はこれの大部分を新しく紹介したはずです。 – bjstone15
副作用として、 'MySQL 4.1以上で提供される機能にアクセスできるようにする' OO MySQLiクラスを使うべきです。 – vimist