html表单数据不会用php处理提交,我需要启用远程访问吗?

bakd9h0s  于 2021-06-24  发布在  Mysql
关注(0)|答案(2)|浏览(311)

所以我做了一个简单的表单,并试图发布到我的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,也不能让它连接到我的数据库来测试文件,我一直被告知我的用户和密码是不正确的,但它肯定不是。

50few1ms

50few1ms1#

你需要更新你从godaddy那里得到的数据库凭证

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

之后,它将成功地将数据保存到数据库中。希望对你有用。

wqlqzqxt

wqlqzqxt2#

你发布的代码中有错误。

$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"]."')";

删除查询中的“addition”
试试这个,检查一下

相关问题