skip to Main Content

So I made a simple form and am trying to post to a database i made on my GoDaddy Cpanel. I’m not sure if maybe I’m not enabling something on the server side or if I just did something goofy in my code. I hit submit to submit my form and I get “mysite.com is currently unable to handle this request”

here is my html form:

<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>

And my php to handle the form:

<?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);
?>

UPDATE: I updated the PHP code to what I have now, I installed PHPStorm and can’t get that to connect to my database to test the file either, I keep getting told that my User and password is incorrect, but it definitely is not.

2

Answers


  1. Some Error in the code you have posted.

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

    and

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

    In the below query you have one extra single quote remove that.

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

    Remove addition ‘ in the query

    Try this and check

    Login or Signup to reply.
  2. You need to update your database credentials which you got from GoDaddy here

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

    And after that it should successfully save the data to the database. Hope it works for you.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search