*Beginner* Connecting MAMP to phpMyAdmin for an SQL database of forms created in HTML/alternative?

php sql phpmyadmin mamp bluehost

640 просмотра

1 ответ

4 Репутация автора

I'm currently trying to connect a PHP file in MAMP to an SQL database table already created under phpMyAdmin via Bluehost. One issue that comes across are two errors that occur when opening the databse.php file as HTML:

Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES) in /Users/*******/Desktop/Local Host/webpage#2/database.php on line 8.

Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in /Users/*******/Desktop/Local Host/webpage#2/database.php on line 13.

Once this is connected to my MAMP how do I connect to phpMyAdmin or is there a preferred route using only my Bluehost account.

I'm currently trying to create a database for forms using HTML->PHP->sql. The PHP file that collects the database info is fine and my "database.php" w/ errors is:

<?php

$host='localhost';
$user='root';
$pass='root';
$db='mdonnerm_sfddb';

$con=mysqli_connect($host,$user,$pass,$db);
if($con)
    echo 'connected succefully to mydb database';

$sql="insert into form (Name, Gender, Email, Comment) values ('flankh', 'flank@gmail.com', 'male', 'hello world')";
$query=mysqli_query($con,$sql);
if($query)
    echo 'data inserted succefully';
?>

Is there an alternative that is used to connecting HTML forms to PHP (processing AND database PHP files required or just an individual file) to SQL?

Also, is there a way to use a single PHP file for multiple form entries or does each form require a new processing PHP file?

Автор: Flankjank Источник Размещён: 18.07.2016 08:11

Ответы (1)


0 плюса

795 Репутация автора

change your code to

$host='localhost';
$user='root';
$pass='root';
$db='mdonnerm_sfddb';

$conn = mysqli_connect($host, $root, $pass, $db);
if (!$conn) {
   die('Could not connect: ' . mysqli_error());
}
else
   echo 'Connected successfully';


$sql="insert into form (Name, Gender, Email, Comment) values ('flankh', 'flank@gmail.com', 'male', 'hello world')";
$query=mysqli_query($con,$sql);
if($query)
   echo 'data inserted succefully';
else
{
  echo "ERROR: Could not able to execute $query. " . mysqli_error($con);
}

or use object oriented method for mysqli

$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
Автор: noushid p Размещён: 18.07.2016 08:39
Вопросы из категории :
32x32