两文件 PHP 联系表

发布于 2024-11-01 21:04:07 字数 2361 浏览 1 评论 0原文

pswindex.php 部分似乎工作正常,但处理程序抛出内部服务器错误(500)。

索引.php

    <div id="contact">
        <h1>Contact us</h1>
        <form id="ContactForm" method="post" action="submit.php">
            <p>
                <label>Name<span>(optional)</span></label>
                <input id="name" name="name" class="inplaceError" maxlength="120" type="text" autocomplete="on"/>`enter code here`
                <span class="error" style="display:none;"></span>
            </p>
            <p>
                <label>Email<span>(optional)</span></label>
                <input id="email" name="email" type="text" />
            </p>
            <p>
                <label>Subject<span>(optional)</span></label>
                <input id="website" name="website" />
            </p>
            <p>
                <label>Your message<br /> <span>700 characters allowed</span></label>
                <textarea id="message" name="message" cols="6" rows="5"></textarea>
            </p>
            <p class="submit">
                <input id="send" type="submit" value="Submit" name="submit"/>
                <span id="loader" class="loader" style="display:none;"></span>
            </p>
    <input id="newcontact" name="newcontact" type="hidden" value="1"></input>
        </form>

submit.php -->


if(isset($_POST['submit'])) {
   $name = $_POST['name'];
   $email = $_POST['email'];
   $website = $_POST['website']; //subject
   $message = $_POST['message'];

   $connection = mysql_connect ("localhost", "root", "pswd") or die ('DB connection fail:' .mysql_error());
   mysql_select_db ("contactform");
   $query = "INSERT INTO contact (pk_contact, name, email, website, message, added_date)VALUES ('NULL','$name','$email','$sub','$msg','NULL')";
   //good to know about the quotes, but the page still insist there's an error
   mysql_query($query) or die ('Error uploading DB');
   mysql_close($connection);
   echo "<span id="success_message" class="success">YAY! It worked.</span>";
} else {
   echo "<span class='error'>Try again.</span>";
}

pswThe index.php part seems to work fine, but the handler throws a internal server error (500).

index.php

    <div id="contact">
        <h1>Contact us</h1>
        <form id="ContactForm" method="post" action="submit.php">
            <p>
                <label>Name<span>(optional)</span></label>
                <input id="name" name="name" class="inplaceError" maxlength="120" type="text" autocomplete="on"/>`enter code here`
                <span class="error" style="display:none;"></span>
            </p>
            <p>
                <label>Email<span>(optional)</span></label>
                <input id="email" name="email" type="text" />
            </p>
            <p>
                <label>Subject<span>(optional)</span></label>
                <input id="website" name="website" />
            </p>
            <p>
                <label>Your message<br /> <span>700 characters allowed</span></label>
                <textarea id="message" name="message" cols="6" rows="5"></textarea>
            </p>
            <p class="submit">
                <input id="send" type="submit" value="Submit" name="submit"/>
                <span id="loader" class="loader" style="display:none;"></span>
            </p>
    <input id="newcontact" name="newcontact" type="hidden" value="1"></input>
        </form>

submit.php -->


if(isset($_POST['submit'])) {
   $name = $_POST['name'];
   $email = $_POST['email'];
   $website = $_POST['website']; //subject
   $message = $_POST['message'];

   $connection = mysql_connect ("localhost", "root", "pswd") or die ('DB connection fail:' .mysql_error());
   mysql_select_db ("contactform");
   $query = "INSERT INTO contact (pk_contact, name, email, website, message, added_date)VALUES ('NULL','$name','$email','$sub','$msg','NULL')";
   //good to know about the quotes, but the page still insist there's an error
   mysql_query($query) or die ('Error uploading DB');
   mysql_close($connection);
   echo "<span id="success_message" class="success">YAY! It worked.</span>";
} else {
   echo "<span class='error'>Try again.</span>";
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

勿挽旧人 2024-11-08 21:04:07

我认为您的查询字符串有错误。它应该看起来像

$query = "INSERT INTO contact (name, email, website, message, added_date)VALUES ('$name','$email','$sub','$msg',NULL)";

双引号正在分解你的字符串,并且不同的部分没有被连接。

I think you've got an error with your query string. It should look like

$query = "INSERT INTO contact (name, email, website, message, added_date)VALUES ('$name','$email','$sub','$msg',NULL)";

The double quotes were breaking up your string, and the different parts weren't being concatenated.

如果没结果 2024-11-08 21:04:07

正如米克西托提到的。您需要删除 NULL 周围的引号。

 $query = "INSERT INTO contact (pk_contact, name, email, website, message, added_date)VALUES (NULL,'$name','$email','$sub','$msg',NULL)";

假设您已设置 mysql 表,因此 added_date 字段是 mysql 时间戳格式,尝试在表中输入 'NULL' 将导致 mysql 错误。

还要确保 mysql 表允许在 pk_contactadded_date 字段中输入空值。

As Mikecito mentioned. You'll want to remove the quotes around NULL.

 $query = "INSERT INTO contact (pk_contact, name, email, website, message, added_date)VALUES (NULL,'$name','$email','$sub','$msg',NULL)";

Assuming you have set you mysql table so the added_date field is a mysql timestamp format, attempting to enter 'NULL' into the table will result in a mysql error.

Also make sure the mysql table allows null values to be entered into the pk_contact and added_date fields.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文