Monday, August 17, 2020

PHPMYADMIN DATABASE CONNECTION IN PHP

 Configuration file: config.php

<?php
$server = "localhost";
$user = "databaseUser";
$password = "dbPassword";
$database = "databaseName";
// Create connection
$link = new mysqli($server, $user, $password, $database);

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

 Form-Action file: action.php

<?php
include_once 'config.php';
$name = $company = $email = $phone = $remark = '';
if(isset($_POST['submit']))
{  
    error_log("ss");
$name = $_POST['name'];
$company = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$remark = $_POST['message'];
$sql = "INSERT INTO tableName (name,company,email,phone,remark) 
                VALUES 
                ('$name','$company','$email','$phone','$remark')";
if (mysqli_query($link, $sql)) {
error_log("New record created successfully !");
echo "<div class='alert alert-success' style='margin-top:40px'>
                <strong>Success!</strong> Thank you for submitting your query, 
                        We'll get back to you soon!
             </div>";
//header("Location: http://www.website.in");
header("Refresh: 5;url='https://www.website.in'");
} else {
error_log("Error: " . $sql . " " . mysqli_error($link));
echo "<div class='alert alert-warning' style='margin-top:40px'>
                <strong>Warning!</strong> Something went wrong. Try again!
            </div>";
//header("Location: http://www.website.in");
header("Refresh: 5;url='https://www.website.in'");
}
mysqli_close($link);
}
?>
phpmyadmin
phpMyAdmin is one of the most popular applications for MySQL database management. It is a free tool written in PHP.



No comments:

Post a Comment

TODO PROJECT IN REACT JS USING ARRAY HOOK, COMPONENT AND SPREAD OPERATOR

 App.jsx import   React , {  useState  }  from   "react" ; import   TodoList   from   "./TodoList" ; const   App  = ()  ...