2011-10-28 22 views
0

求这个PHP页面(的作品)与该网站输入转换为电子邮件输入转换WebsiteField到emailField

我已经改变了所有的websiteField项目emailField包括电子邮件正则表达式,但它带来的回来自服务器的错误消息。 500 - 内部服务器错误。 您正在查找的资源存在问题,并且无法显示。

<?php 

    require "config.php"; 
    require "connect.php"; 

    if(isset($_POST['submitform']) && isset($_POST['txn_id'])) 
    { 
    $_POST['nameField'] = esc($_POST['nameField']); 
    $_POST['websiteField'] = esc($_POST['websiteField']); 
    $_POST['messageField'] = esc($_POST['messageField']); 

    $error = array(); 

    if(mb_strlen($_POST['nameField'],"utf-8")<2) 
    { 
     $error[] = 'Please fill in a valid name.'; 
    } 

    if(mb_strlen($_POST['messageField'],"utf-8")<2) 
    { 
     $error[] = 'Please fill in a longer message.'; 
    } 

    if(!validateURL($_POST['websiteField'])) 
    { 
     $error[] = 'The URL you entered is invalid.'; 
    } 

    $errorString = ''; 
    if(count($error)) 
    { 
     $errorString = join('<br />',$error); 
    } 
    else 
    { 
     mysql_query(" INSERT INTO dc_comments (transaction_id, name, url, message) 
         VALUES (
          '".esc($_POST['txn_id'])."', 
          '".$_POST['nameField']."', 
          '".$_POST['websiteField']."', 
          '".$_POST['messageField']."' 
         )"); 

     if(mysql_affected_rows($link)==1) 
     { 
      $messageString = '<a href="donate.php">You were added to our donor list! &raquo;</a>'; 
     } 
    } 
} 

?> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Thank you!</title> 

<link rel="stylesheet" type="text/css" href="styles.css" /> 

</head> 

<body class="thankyouPage"> 

<div id="main"> 
    <h1>Thank you!</h1> 
    <h2>Add Yourself to our Donor List. </h2> 

    <div class="lightSection"> 
     <form action="" method="post"> 
      <div class="field"> 
       <label for="nameField">Name</label> 
       <input type="text" id="nameField" name="nameField" /> 
      </div> 

      <div class="field"> 
       <label for="websiteField">Web Site</label> 
       <input type="text" id="websiteField" name="websiteField" /> 
      </div> 

      <div class="field"> 
       <label for="messageField">Message</label> 
       <textarea name="messageField" id="messageField"></textarea> 
      </div> 

      <div class="button"> 
       <input type="submit" value="Submit" /> 
       <input type="hidden" name="submitform" value="1" /> 
       <input type="hidden" name="txn_id" value="<?php echo $_POST['txn_id']?>" /> 
      </div> 
     </form> 

     <?php 
     if($errorString) 
     { 
      echo '<p class="error">'.$errorString.'</p>'; 
     } 
     else if($messageString) 
     { 
      echo '<p class="success">'.$messageString.'</p>'; 
     } 
     ?> 

    </div> 


</body> 
</html> 


<?php 

function esc($str) 
{ 
    global $link; 

    if(ini_get('magic_quotes_gpc')) 
      $str = stripslashes($str); 

    return mysql_real_escape_string(htmlspecialchars(strip_tags($str)),$link); 
} 

function validateURL($str) 
{ 
    return preg_match('/(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:\/~\+#]*[\w\-\@?^=%&amp;\/~\+#])?/i',$str); 
} 
?> 

这是一些以反映电子邮件,而不是网站

<?php 

require "config.php"; 
require "connect.php"; 

if(isset($_POST['submitform']) && isset($_POST['txn_id'])) 
{ 
    $_POST['nameField'] = esc($_POST['nameField']); 
    $_POST['emailField'] = esc($_POST['emailField']); 
    $_POST['messageField'] = esc($_POST['messageField']); 

    $error = array(); 

    if(mb_strlen($_POST['nameField'],"utf-8")<2) 
    { 
     $error[] = 'Please fill in a valid name.'; 
    } 

    if(mb_strlen($_POST['messageField'],"utf-8")<2) 
    { 
     $error[] = 'Please fill in a longer message.'; 
    } 

    if(!validate_email($_POST['emailField'])) 
    { 
     $error[] = 'The email you entered may be invalid! Please check same.'; 
    } 

    $errorString = ''; 
    if(count($error)) 
    { 
     $errorString = join('<br />',$error); 
    } 
    else 
    { 
     mysql_query(" INSERT INTO dc_comments (transaction_id, name, email, message) 
         VALUES (
          '".esc($_POST['txn_id'])."', 
          '".$_POST['nameField']."', 
          '".$_POST['emailField']."', 
          '".$_POST['messageField']."' 
         )"); 

     if(mysql_affected_rows($link)==1) 
     { 
      $messageString = '<a href="donate.php">You were added to our donor list! &raquo;</a>'; 
     } 
    } 
} 

?> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Thank you!</title> 

<link rel="stylesheet" type="text/css" href="styles.css" /> 

</head> 

<body class="thankyouPage"> 

<div id="main"> 
    <h1>Thank you for your support!</h1> 
    <h2>Add your name to the donor list. </h2> 

    <div class="lightSection"> 
     <form action="" method="post"> 
      <div class="field"> 
       <label for="nameField">Name</label> 
       <input type="text" id="nameField" name="nameField" /> 
      </div> 

      <div class="field"> 
       <label for="emailField">Email</label> 
       <input type="text" id="emailField" name="emailField" /> 
      </div> 

      <div class="field"> 
       <label for="messageField">Message</label> 
       <textarea name="messageField" id="messageField"></textarea> 
      </div> 

      <div class="button"> 
       <input type="submit" value="Submit" /> 
       <input type="hidden" name="submitform" value="1" /> 
       <input type="hidden" name="txn_id" value="<?php echo $_POST['txn_id']?>" /> 
      </div> 
     </form> 

     <?php 
     if($errorString) 
     { 
      echo '<p class="error">'.$errorString.'</p>'; 
     } 
     else if($messageString) 
     { 
      echo '<p class="success">'.$messageString.'</p>'; 
     } 
     ?> 

    </div> 


</body> 
</html> 


<?php 

function esc($str) 
{ 
    global $link; 

    if(ini_get('magic_quotes_gpc')) 
      $str = stripslashes($str); 

    return mysql_real_escape_string(htmlspecialchars(strip_tags($str)),$link); 
} 

function validate_email($str) 
{ 
    return preg_match('.*[email protected]*?\...*', $str); 
} 
?> 

为什么电子邮件没有按计划工作的变化在同一页,是方法正确?

我这个DonationScript

+0

如上所示,“500服务器错误”。这听起来像一个实际的托管错误,而不是你的PHP代码的问题。你是否编辑过.htaccess文件? – Luke

+0

您有权访问error_log的内容并将错误消息放在此处吗? – jprofitt

回答

0

你的问题的工作可能会在你的正则表达式中,*是在你的代码示例一个未知的改性剂。试试这个...完全删除验证电子邮件功能。然后换

if(!validate_email($_POST['emailField'])) 

if (!filter_var($_POST['emailField'], FILTER_VALIDATE_EMAIL)) 

,看看是否适合你。

+0

嗨奥斯汀最好,我完全替换了验证函数,并且第一次工作。好的工作,谢谢你。这是否意味着我正在使用低质量的正则表达式来验证电子邮件! – Webiter