PHP Developers Network

Connecting php to XAMPP
Page 1 of 1

Author:  Jano12 [ Tue Aug 13, 2013 1:49 pm ]
Post subject:  Connecting php to XAMPP

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;

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 :

$host = “localhost”;
$user = “admin”;
$password = “”;
$database = “CustomerDirectory”;

switch (@$_POST[‘Button’])
case “Login”:
(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 !!

Author:  requinix [ Tue Aug 13, 2013 3:02 pm ]
Post subject:  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?

Author:  Jano12 [ Wed Aug 14, 2013 3:13 pm ]
Post subject:  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...

Author:  requinix [ Wed Aug 14, 2013 3:30 pm ]
Post subject:  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.

Author:  akhilesh1010 [ Fri Aug 23, 2013 2:13 am ]
Post subject:  Re: Connecting php to XAMPP

You Should check your database credential check $user with root :P

Author:  jangmi [ Mon Mar 10, 2014 6:30 am ]
Post subject:  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

Author:  hiltorion [ Mon Sep 08, 2014 5:38 am ]
Post subject:  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.

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB® Forum Software © phpBB Group