Answer the question
In order to leave comments, you need to log in
How to fix mysql database connection error?
Hello!
I'm trying to run PHP on openserver.
Created a database using phpmyadmin.
Once I tried, I can not get a connection to the MySQL database in any way
<?php
$first_name = $_POST['firstname'];
$last_name = $_POST['lastname'];
$when_it_happened = $_POST['whenithappened'];
$how_long = $_POST['howlong'];
$how_many = $_POST['howmany'];
$alien_description = $_POST['aliendescription'];
$what_they_did = $_POST['whattheydid'];
$fang_spotted = $_POST['fangspotted'];
$email = $_POST['email'];
$other = $_POST['other'];
$dbc = mysqli_connect('127.0.0.1:3306', 'mysql', 'mysql', 'aliendatabase')
or die ('Ошибка соединения с MySQL - сервером.');
$query = "INSERT INTO aliens_abduction (first_name, last_name, when_it_happened, how_long, " .
"how_many, alien_description, what_they_did, fang_spotted, other, email) " .
"VALUES ('$first_name', '$last_name', '$when_it_happened', '$how_long', '$how_many', " .
"'$alien_description', '$what_they_did', '$fang_spotted', '$other', '$email')";
$result = mysqli_query($dbc, $query) or die ('Ошибка при выполнении запроса к базе данных.');
mysqli_close($dbc);
?>
Answer the question
In order to leave comments, you need to log in
if(!isset($_SESSION[ 'admincp' ]) && !isset($_SESSION['login'])))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question