-1

I’m having trouble successfully INSERTing information into a database I created. I tried several different alternatives I found on the internet and I was hoping someone could help. From what I can tell I’m connecting to the database without a problem, the data is just not being submitted into it. I kept it very simple just for testing purposes to no avail. It’s probably something simple that a more experienced programmer could help out easily.

I’m running a server through A2Hosting that is running “Server version: 10.2.18-MariaDB-cll-lve - MariaDB Server” “Php version: 5.6.30”

Here is the code I have running(for security I’m substituted in info): I did the “dummy checks” with data base table and field names, username and case of letters too.

config.php:

<?php
$host = "server.a2hosting.com";
$userName = "username";
$password = "password";
$dbName = "Database";

// Create database connection
$conn = mysql_connect ($host, $userName, $password, $dbName);

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

Html file - index.html:

<html><body> <form method="post" action="index.php"> <input type='text' name='first_name' id='first_name'> <input type='text’ name='last_name'> <input type=submit value="Submit"> </form>
 </body></html>

Php file - index.php

 <?  include("config.php"); 
// has the access info for the DB, how to connect

 // create a variable
$first_name=$_POST['first_name'];
$last_name=$_POST['last_name'];

 $query = "INSERT INTO Contact_Information (HOW_name, address) VALUES
 ('$first_name', '$last_name'); "; mysql_query($query); mysql_close();

 ?>


 <html> <head> <meta HTTP-EQUIV="REFRESH" content="0; url=form1.php">
 </head> </html>
  • mysql_* functions are deprecated as of PHP 5.5.0, and removed as of PHP 7.0.0. Switch your code to use [PDO](https://secure.php.net/manual/en/pdo.prepared-statements.php) or [mysqli](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) instead. Be sure to use prepared statements and parameter binding, so **you'll never have to worry about quoting issues again.** – aynber Dec 11 '18 at 18:47
  • Please don't use the `mysql` library. It has been deprecated for a while and has been removed **completely** from PHP7. – rpm192 Dec 11 '18 at 18:48
  • What's not working, can you share an error message? – rpm192 Dec 11 '18 at 18:48
  • For one `type='text’` < contains a curly quote. – Funk Forty Niner Dec 11 '18 at 18:49
  • Your code failed in too many ways. What you have in your db declaration doesn't do what you think it does. – Funk Forty Niner Dec 11 '18 at 18:50

1 Answers1

-2

$query = "INSERT INTO contact_inforamarion(how_name, address) VALUES('$first_name', '$last_name');";

$result = mysqli_query($conn, $query);

Query and result should be like this.