drnxnbf199049 2013-03-29 01:46 采纳率: 100%
浏览 29
已采纳

PHP注册表和数据库错误

I've asked a few questions on here and got lots of help, so I will thank in advance for my next question. I've been trying to create Registration System for my Scout Group (Registering for Camps) and I've gotten stuck up to the point where I can't send the data from the form into the database, and then send a confirmation email using the PHP Mail function.

Bellow is my form code:

    <form action="include/spud/registration.php">

                          <h2>Group Information:</h2>
                          <table width="100%" border="0" cellspacing="10">
                            <tr>
                              <td>Group Name (# &amp; Name):
                              <br />
                              <div class="input-control text">
                                  <input type="text" name="group_name" />
                                  <button class="btn-clear"></button>
                              </div>
                              </td>
                            </tr>
                            <tr>
                              <td>Group Location (City it is located in: e.g. Mississauga):
                              <br />
                              <div class="input-control text">
                                  <input type="text" name="group_location" />
                                  <button class="btn-clear"></button>
                              </div>
                              </td>
                            </tr>
                            <tr>
                              <td>Number of Youth Attending:
                              <br />
                              <div class="input-control text">
                                  <input type="text" name="group_attending" />
                                  <button class="btn-clear"></button>
                              </div>
                              </td>
                            </tr>
                          </table>
                          <h2>Contact Information:</h2>
                          <table width="100%" border="0" cellspacing="10">
                            <tr>
                              <td width="50%">First Name:
                              <br />
                              <div class="input-control text">
                                  <input type="text" name="name_first" />
                                  <button class="btn-clear"></button>
                              </div>
                              </td>
                              <td>Last Name:
                              <br />
                              <div class="input-control text">
                                  <input type="text" name="name_last" />
                                  <button class="btn-clear"></button>
                              </div>
                              </td>
                            </tr>
                            <tr>
                              <td>Address:
                              <br />
                              <div class="input-control text">
                                  <input type="text" name="address" />
                                  <button class="btn-clear"></button>
                              </div>
                              </td>
                              <td>Address 2 (Optional):
                              <br />
                              <div class="input-control text">
                                  <input type="text" name="address2" />
                                  <button class="btn-clear"></button>
                              </div>
                              </td>
                            </tr>
                            <tr>
                              <td>City:
                              <br />
                              <div class="input-control text">
                                  <input type="text" name="city" />
                                  <button class="btn-clear"></button>
                              </div>
                              </td>
                              <td>Province or State:
                              <br />
                              <div class="input-control text">
                                  <input type="text" name="prov_state" />
                                  <button class="btn-clear"></button>
                              </div>
                              </td>
                            </tr>
                          </table>
                          <table width="100%" border="0" cellspacing="10">
                            <tr>
                              <td>Country:
                              <br/>
                              <div class="input-control select">
                                  <select>
                                    <option selected>Choose...</option>
                                    <option name="country">Canada</option>
                                    <option name="country">United States</option>
                                    <option name="country">Scotland</option>
                                    <option name="country">Another Country</option>
                                  </select>
                              </div>
                              </td>
                            </tr>
                            <tr>
                              <td>Postal Code (ZIP):
                              <br />
                              <div class="input-control text">
                                  <input type="text" name="zip_code" />
                                  <button class="btn-clear"></button>
                              </div>
                              </td>
                            </tr>
                          </table>
                          <table width="100%" border="0" cellspacing="10">
                            <tr>
                              <td width="50%">Telephone:
                              <br />
                              <div class="input-control text">
                                  <input type="text" name="telephone" />
                                  <button class="btn-clear"></button>
                              </div>
                              </td>
                              <td>Telephone (Residential or Business: Optional):
                              <br />
                              <div class="input-control text">
                                  <input type="text" name="telephone2" />
                                  <button class="btn-clear"></button>
                              </div>
                              </td>
                            </tr>
                          </table>
                          <table width="100%" border="0" cellspacing="10">
                            <tr>
                              <td>Email:
                              <br />
                              <div class="input-control text">
                                  <input type="text" name="email" />
                                  <button class="btn-clear"></button>
                              </div>
                              </td>
                            </tr>
                          </table>
                          <div class="place-left">
                              <button type="submit">Submit</button>
                              <button type="reset">Reset</button>
                          </div>
                          <div class="place-right">
                              <a href="#info" class="button">Spud Camp Information</a>
                          </div>
                        </form>

Then it sends it to the database stage:

    <?php

require_once('../database.php');

/*
* Insert the data into the Database
*/

    $qry=mysql_query("INSERT INTO 

    spudcamp(group_name,group_location,group_attending,name_first,name_last,address,address2,city,prov_state,country,zip_code,telephone,telephone2,email)

    VALUES('$_POST[group_name]','$_POST[group_location]','$_POST[group_attending]','$_POST[name_first]','$_POST[name_last]','$_POST[address]','$_POST[address2]','$_POST[city]','$_POST[prov_state]','$_POST[country]','$_POST[zip_code]','$_POST[telephone]','$_POST[telephone2]','$_POST[email]', NOW() )

    ", $con);

if(!$qry)
{
    die("Query Failed: ". mysql_error());
}
else
{
    header('location:../../spud-camp.php');
}

/*
* Send an Email to Administration and to the Signed up person
*/

include('receipt_email.php');

    ?>

then the receipt_email.php stage:

    <?php

    /*
    * Receipt Emailer
    */


    $message = '

    <html>
    <body style="color: #000;font-family:arial;">


    <p>Thank you&#44; <b>';

    $message .= $_POST[name_first] . ' ';
    $message .= $_POST[name_last];

    $message .= '</b>&#44; for your submission&#46;<br>';
    $message .=  'We hope that the <b>';
    $message .= $_POST[group_name];
    $message .= '</b><br>
                  <b>Please print this page for your records.</b><br><BR>
                      Your registration submitted on ';
    $message .= date('l jS \of F Y h:i:s A');
    $message .= ' is as follows&#58;<br><br>
      Registration &#35;&#58; <B>';

    $message .= '</B><br>
      Group Name&#58; <B>';
    $message .= $_POST[group_name];
    $message .= '</B><br>
      First Name&#58; <B>';
    $message .= $_POST[name_first];  
    $message .= '</B>  <br>
      Last Name&#58; <B>';
    $message .= $_POST[name_last];
    $message .= '</B><br>
     Address 1&#58; <B>';
    $message .=  $_POST[address1];
    $message .=  '</B><br>
      Address 2&#58; <B>';
    $message .=  $_POST[address2];
    $message .=  '</B><br>
      City&#58; <B>';
    $message .=  $_POST[city];
    $message .=  '</B><br>
      Prov&#47;State&#58; <B>';

    $message .=  $_POST[prov_state];
    $message .=  '</B><br>
      Postal Code&#58; <B>';
    $message .=  $_POST[zip_code];
    $message .=  '</B><br>
      Country&#58; <B>';
    $message .=  $_POST[country];
    $message .=  '</B><br>
      Telephone &#35;&#58; <B>';
    $message .=  $_POST[telephone];
    $message .=  '</B><br>
      Business Phone &#35;&#58; <B>';
    $message .=  $_POST[telephone2];
    $message .=  '</B><br>
      E&#45;mail&#58; <B>';
    $message .=  $_POST[email];
    $message .=  '</B><br>
      &#35; Attending&#58; <B>';
    $message .=  $_POST[group_attending];
    $message .=  '</B></p>';

    $message .= '
    </body>
    </html>
    ';

    // multiple recipients
    $to  = $_POST[email] . ", "; // note the comma
    $to .= '';

    // subject
    $subject = '';

    // To send HTML mail, the Content-type header must be set
    $headers .= 'MIME-Version: 1.0' . "
";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "
";

    // Additional headers
    $headers .= 'To: Registrant <' . $_POST[email] . ">
";
    $headers .= ' <>' . "
";

    // Mail it
    mail($to, $subject, $message, $headers);


    ?>

I have removed some places, that way i don't have my email on the page for spammers. Anyways thanks in advance I really will appreciate it :D

  • 写回答

2条回答 默认 最新

  • dqrfdl5708 2013-03-29 01:51
    关注

    close! with line 9:

    $qry=mysql_query("INSERT INTO...
    

    theres a NOW() at the end:

    ...'$_POST[email]', NOW())
    

    remove the NOW(), so just

    ...'$_POST[email]')
    

    see how that goes :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 数据库数据成问号了,前台查询正常,数据库查询是?号
  • ¥15 算法使用了tf-idf,用手肘图确定k值确定不了,第四轮廓系数又太小才有0.006088746097507285,如何解决?(相关搜索:数据处理)
  • ¥15 彩灯控制电路,会的加我QQ1482956179
  • ¥200 相机拍直接转存到电脑上 立拍立穿无线局域网传
  • ¥15 (关键词-电路设计)
  • ¥15 如何解决MIPS计算是否溢出
  • ¥15 vue中我代理了iframe,iframe却走的是路由,没有显示该显示的网站,这个该如何处理
  • ¥15 操作系统相关算法中while();的含义
  • ¥15 CNVcaller安装后无法找到文件
  • ¥15 visual studio2022中文乱码无法解决