Connecting php to XAMPP

Discussion of testing theory and practice, including methodologies (such as TDD, BDD, DDD, Agile, XP) and software - anything to do with testing goes here. (Formerly "The Testing Side of Development")

Moderator: General Moderators

Post Reply
Jano12
Forum Newbie
Posts: 4
Joined: Mon Aug 12, 2013 6:49 pm

Connecting php to XAMPP

Post by Jano12 »

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 !!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Connecting php to XAMPP

Post by requinix »

What is the exact error message? Have you read it carefully for any clue as to what the problem is?
Jano12
Forum Newbie
Posts: 4
Joined: Mon Aug 12, 2013 6:49 pm

Re: Connecting php to XAMPP

Post by Jano12 »

I have found the problem the $user should be 'root' and not 'admin' before connecting and it's very important...
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Connecting php to XAMPP

Post by requinix »

Do not use root. Create a different user, like "admin" if you want, and give them the permissions they need.
akhilesh1010
Forum Newbie
Posts: 15
Joined: Thu Aug 22, 2013 1:56 am

Re: Connecting php to XAMPP

Post by akhilesh1010 »

You Should check your database credential check $user with root :P
jangmi
Forum Newbie
Posts: 11
Joined: Sat Mar 08, 2014 7:39 am

Re: Connecting php to XAMPP

Post by jangmi »

you need to check the exact mysql account, you can go to http://localhost/phpmyadmin and click to User tab to see account list
hiltorion
Forum Newbie
Posts: 1
Joined: Mon Sep 08, 2014 5:31 am

Re: Connecting php to XAMPP

Post by hiltorion »

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.
Post Reply