Hello , I have a problem running php code that will connect to a database and run on xampp.
I took the codes and the example from a book called php&MySql for dummies a 6in1.
That's the database I have to create :
CREATE DATABASE CustomerDirectory;
CREATE TABLE Customer (
user_name VARCHAR(20) NOT NULL,
create_date DATE NOT NULL,
password VARCHAR(255) NOT NULL,
last_name VARCHAR(50),
first_name VARCHAR(40),
street VARCHAR(50),
city VARCHAR(50),
state CHAR(2),
zip CHAR(10),
email VARCHAR(50),
phone CHAR(15),
fax CHAR(15),
PRIMARY KEY(user_name) )
I have run this code in phpAdmin in XAMPP and created the Data base, however I can't connect to it .
Here's the connection script :
<?php
$host = “localhost”;
$user = “admin”;
$password = “”;
$database = “CustomerDirectory”;
switch (@$_POST[‘Button’])
{
case “Login”:
include(“dbstuff.inc”);
(THE ERROR LINE )$cxn = mysqli_connect($host,$user,$password,$database)
or die(“Query died: connect”);
$sql = “SELECT user_name FROM Customer
WHERE user_name=’$_POST[fusername]’”;
$result = mysqli_query($cxn,$sql)
or die(“Query died: fuser_name”);
The error is it can't connect to DB what can I do with it , please help !!
Connecting php to XAMPP
Moderator: General Moderators
Re: Connecting php to XAMPP
What is the exact error message? Have you read it carefully for any clue as to what the problem is?
Re: Connecting php to XAMPP
I have found the problem the $user should be 'root' and not 'admin' before connecting and it's very important...
Re: Connecting php to XAMPP
Do not use root. Create a different user, like "admin" if you want, and give them the permissions they need.
-
- Forum Newbie
- Posts: 15
- Joined: Thu Aug 22, 2013 1:56 am
Re: Connecting php to XAMPP
You Should check your database credential check $user with root 

Re: Connecting php to XAMPP
you need to check the exact mysql account, you can go to http://localhost/phpmyadmin and click to User tab to see account list
Re: Connecting php to XAMPP
You're running the same code. If there's a flaw on one site then it'll show on the other site too. And if you literally run the exact same code then it's actually better: you fix the bug for one site and it's fixed for all the others.