Cannot submit data to database

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Cannot submit data to database

Postby jerrittpace » 22. November 2015 21:41

I am having some problems getting form data submitted to a mysql database in apache.

I can connect to the database, but cannot get the data to successfully get entered into the database.

My form looks like this:

Code: Select all
    <form action="submit_info.php" method="post">
      <ul>
        
        
<li>
          <p class="left">
            <label for="first_name"></label>
            <input type="text" name="first_name" placeholder="First Name" />
          </p>
          <p class="pull-right">
            <label for="last_name"></label>
            <input type="text" name="last_name" placeholder="Last Name" />      
          
</p>
        </li>
        
        
<li>
          <p>
            <label for="email"> <span class="req"></span></label>
            <input type="email" name="email" placeholder="Your Email " />
          </p>
        </li>
        <li> 
        
        
        
         
<p>
      
           
<input type="text" name="phone_number" placeholder="Phone Number" />
         </p>
         </li>
        
        
<li><div class="divider"></div></li>
        <li>
          <label for="comments">Comments</label>
          <textarea cols="46" rows="3" name="comments"></textarea>
        </li>
        
        
<li>
          <input class="btn btn-submit" type="submit" value="Submit" />
        </li>
        
      
</ul>
    </form


The connect page, mysqli_connect.php, which works, is like this:

Code: Select all
<?php
$servername 
= "127.0.0.1";
$username = "jerrittpace";
$password = "553597";
$dbname = "contact_me_jerrittpace.com";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>



Then the submit_info.php page, which I can't get to work, is:

Code: Select all
<?php
include 
'mysqli_connect.php';

if(isset(
$_POST["submit"])){

$sql = "INSERT INTO persons (first_name, last_name, email, phone_number, comments) 

VALUES ('"
.$_POST["first_name"]."','".$_POST["last_name"]."','".$_POST["email"]."', '".$_POST["phone_number"]."', '".$_POST["comments"]."')";

}

?>


My database (named contact_me_jerrittpace.com) is set up like this:

1 ID int(100) UNSIGNED No None Change Change Drop Drop

Primary Primary
Unique Unique
Index Index
Spatial Spatial
Fulltext Fulltext
Distinct values Distinct values

2 first_name text No None Change Change Drop Drop

Primary Primary
Unique Unique
Index Index
Spatial Spatial
Fulltext Fulltext
Distinct values Distinct values

3 last_name text No None Change Change Drop Drop

Primary Primary
Unique Unique
Index Index
Spatial Spatial
Fulltext Fulltext
Distinct values Distinct values

4 email varchar(100) No None Change Change Drop Drop

Primary Primary
Unique Unique
Index Index
Spatial Spatial
Fulltext Fulltext
Distinct values Distinct values

5 phone_number varchar(15) No None Change Change Drop Drop

Primary Primary
Unique Unique
Index Index
Spatial Spatial
Fulltext Fulltext
Distinct values Distinct values

6 comments varchar(500) No None Change Change Drop Drop

Primary Primary
Unique Unique
Index Index
Spatial Spatial
Fulltext Fulltext
Distinct values Distinct values

With selected:Check allWith selected:

I appreciate any help anyone can offer!!

[EDIT by Altrea: changed the subject (yes, you can edit your own post here) and wrapped your code in php BB-Tags]
jerrittpace
 
Posts: 26
Joined: 14. November 2015 18:54
Operating System: windows

Re: Cannot submit data to database

Postby Altrea » 22. November 2015 21:56

Where do you use the $sql variable?
Just saving the statement into a variable will not execute it.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8294
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: Cannot submit data to database

Postby jerrittpace » 22. November 2015 22:47

Oh ok so I guess I am not...

I've tried the following:

Code: Select all
if (mysqli_query($conn, $sql)) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}


but I am getting Undefined variable: sql in C:\xampp\htdocs\contact_me\New folder\submit_info.php on line 21

I really appreciate your help... I think i am going to have to come back to this a little later...sigh, but thank you very much for your help!!
jerrittpace
 
Posts: 26
Joined: 14. November 2015 18:54
Operating System: windows

Re: Cannot submit data to database

Postby Altrea » 23. November 2015 01:12

At the place you are trying to use $sql, this variable is not defined.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8294
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: Cannot submit data to database

Postby jerrittpace » 23. November 2015 17:55

oh I had the variable defined inside the if statement...

Thank you very much for your help!!
jerrittpace
 
Posts: 26
Joined: 14. November 2015 18:54
Operating System: windows


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 77 guests