0

I am unable to send the information from a from into mysql. I get the following error: Fatal error: call to undefined function mysqli_connect()

I know the db connection is working because I am able to send other data into the database. I have added the connection information on the signupcontact.php but that did nothing.

I am not sure what the issue is since the database is connected.

Thanks for your help in advance.

form:

<?php
   echo "<div class='wrapper'>";
   require ('header.php');
   include ('signupcontact.php');
   include ('db_connect2.php');



?>
   <head>
   <title>Contac Information</title>
   <meta charset="utf-8"/>
   <link rel="stylesheet" href="style.css"/>

    </style>
    <script>
    function validateForm() {
    if (document.forms[0].userName.value == "") {
        alert("Name field cannot be empty.");
        return false;
    } //end if
    if (document.forms[0].userLastName.value == "") {
        alert("Last Name field cannot be empty.");
        return false;
    } // end if
    if (document.forms[0].userEmail.value == "") {
        alert("Email field cannot be empty.");
        return false;
    } // end if
    alert ("Successful!");
    return true;
    } //end function validateForm
    </script>
    </head>
    <body>


    <?php
    echo '<form method="POST"
          action="db_connect2.php"
          onsubmit="return validateForm();">
           <fieldset style="width:900px; margin:auto;"> 
           <legend class="pcenter">Subscribe for updates</legend>
<label for="userName">Name: </label><br />
<input type="text" name="userName" id="userName"/><br /><br />
<label for="Last_Name">Last Name: </label><br />
<input type="text" name="userLastName" id="userLastName"/><br /><br />
<label for="userEmail">Email: </label><br />
<input type="text" name="userEmail" id="userEmail"/>
<br /><br />
<input type="submit" value="submit" id="submit"/><br />
</fieldset> 
</form>

dbconnect:

<?php

$conn = mysqli_connect('localhost', 'root', '', 'happy_blog');

if(!$conn) {
    die("connection failed: ".mysqli_connect_error());
}

signupcontact (I added the connection here again to see if it helps, nothing)

<?php
$dBServername = "localhost";
$dBUsername = "root";
$dBPassword = "";
$dBName = "happy_blog";

// Create connection
$conn = mysqli_connect($dBServername, $dBUsername, $dBPassword, $dBName);

// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
    if (isset($_POST['submit'])){
        $Name = $_POST['userName'];
        $LName = $_POST['userLastName'];
        $Email = $_POST['userEmail'];

        $Name = mysqli_real_escape_string($conn,$_POST['userName']);
        $LName = mysqli_real_escape_string($conn,$_POST['userLastName']);
        $Email = mysqli_real_escape_string($conn,$_POST['userEmail']);

        //$sql = "INSERT INTO contact (userName, userLastName, userEmail) VALUES ('".$_POST["userName"]."', '".$_POST["userLastName"]."', '".$_POST["userEmail"]."')";
        $sql = "INSERT INTO contact (userName, userLastName, userEmail) VALUES ($Name, $LName, $Email)";
        $result = mysqli_query($conn, $sql);
if ($conn->query($sql) === TRUE) {
    echo "Form submitted successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();

}
Shadow
  • 33,525
  • 10
  • 51
  • 64
Paola
  • 13
  • 5
  • Instead of include use <b> require</b> also check the browser console of any js code is stopping from posting the data. Also add die (mysql_error ()) for the insert query. – Hp_issei Dec 09 '18 at 07:30
  • thank you. I added these changes and I am still getting the same error: Fatal error: Call to undefined function mysqli_connect(). – Paola Dec 09 '18 at 07:46
  • Please check this: https://stackoverflow.com/questions/15628216/fatal-error-mysqli-connect – Hp_issei Dec 09 '18 at 07:54
  • The mysqli PHP extension is not installed or enabled on your new server. Please install or enable it if already installed. – Rohit Rasela Dec 09 '18 at 08:30
  • That isn't the only thing wrong with your code. You need to quote string values. Plus, `if (isset($_POST['submit'])){...}` will never happen since there is no name attribute for the submit input. Enable error reporting. – Funk Forty Niner Dec 09 '18 at 13:54
  • Thank you guys for your comments. I was able to get this working. – Paola Dec 09 '18 at 16:51

0 Answers0