HTML表单数据不会通过PHP处理提交,我是否需要启用远程访问?

时间:2018-04-24 14:19:37

标签: php mysql phpmyadmin cpanel

所以我做了一个简单的表格,并试图发布到我在GoDaddy Cpanel上制作的数据库。我不确定我是不是在服务器端启用了某些东西,或者我是否在我的代码中做了一些愚蠢的事情。我点击提交提交我的表单,我得到“mysite.com目前无法处理此请求”

这是我的html表单:

<form id="contactForm" action="formdb.php" method="post">

<div class="rGroup">

    <label for="Contact Name">Name: </label>
    <input type="text" name="Name" size="46"><br><br>
    <label for="email">Email:</label>
    <input type="email" name="Email" size="46"><br><br>
    <label for="Contact Number">Phone:</label>
    <input type="tel" name="Phone"><br><br>
    <label for="interest">Interested in:</label><br><br>
    <input type="radio" name="Interest" value="WebDev" checked>Web Development<br>
    <input type="radio" name="Interest" value="SoftDev">Software Development <br>
    <input type="radio" name="Interest" value="Other">Other<br><br><br>
    <label for="Message">Comments:</label><br>
    <textarea name="Message" form="contactForm" rows="8" cols="50" 
    placeholder="Brief description, please submit as rendered."></textarea>
    <input id="submitButt" type="submit" value="Submit">

</div>

</form>

我的php处理表单:

<?php
//Make Database connection.
$dbhost = "localhost";
$dbuser = 'user';
$dbpass = 'password';
$dbname = "InterestedContacts";
$connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);

if(mysqli_connect_errno()){
    die("Database connection failed: " .
    mysqli_connect_error() . ")"
    );
}

//Perform insert of data
$Name = $_POST['clientName'];
$Phone = $_POST['Phone'];
$Email = $_POST['Email'];
$Message = $_POST['Message'];
$Interest = $_POST['Interest'];

//Sanitize data and add escape string
$Name = mysqli_real_escape_string($connection, $Name);
$Phone = mysqli_real_escape_string($connection, $Phone);
$Email = mysqli_real_escape_string($connection, $Email);
$Message = mysqli_real_escape_string($connection, $Message);
$Interest = mysqli_real_escape_string($connection, $Interest);

$query = "INSERT INTO Prospects (clientName, Email, Phone, Message, Interest)
            VALUES ('" .$_POST["clientName"]."','".$_POST["Email"]."','".$_POST["Phone"]."','".$_POST["Message"]."','".$_POST["Interst"]."')";

            $result = mysqli_query($connection, $query);
            //Test to see if query had error_get_last
            if($result){
                //SUCCESS
                header('Location: thankyou.html');
            }else{
                //FAILURE
                die("Database query failed. " . mysqli_error($connection));
            }
            ini_set('display_errors', 1); error_reporting(-1);
            mysqli_close($connection);
?>

更新:我将PHP代码更新为现在的版本,我安装了PHPStorm并且无法连接到我的数据库来测试文件,我不断被告知我的用户和密码不正确,但它绝对不是。

2 个答案:

答案 0 :(得分:1)

您发布的代码中存在一些错误。

$dbpass = "password"; // add semi colon

$Interest = $_POST['Interest']; // angle brace not flower brace

在下面的查询中,您有一个额外的单引号删除它。

$query = "INSERT INTO Prospects (Name, Phone, Email, Message)
            VALUES ('".$_POST["Name"]."','".$_POST["Phone"]."','".$_POST["Email"]."','".$_POST["Interst"]."','".$_POST["Message"]."')";

在查询中删除“添加”

试试这个并检查

答案 1 :(得分:0)

您需要更新从GoDaddy这里获得的数据库凭据

$dbhost = "localhost";
$dbuser = "userInfo";
$dbpass = "password";
$dbname = "databasename";

之后它应该成功将数据保存到数据库中。希望它适合你。