PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Tue May 23, 2017 3:50 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Connecting php to XAMPP
PostPosted: Tue Aug 13, 2013 1:49 pm 
Offline
Forum Newbie

Joined: Mon Aug 12, 2013 6:49 pm
Posts: 4
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 !!


Top
 Profile  
 
PostPosted: Tue Aug 13, 2013 3:02 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6418
Location: WA, USA
What is the exact error message? Have you read it carefully for any clue as to what the problem is?


Top
 Profile  
 
PostPosted: Wed Aug 14, 2013 3:13 pm 
Offline
Forum Newbie

Joined: Mon Aug 12, 2013 6:49 pm
Posts: 4
I have found the problem the $user should be 'root' and not 'admin' before connecting and it's very important...


Top
 Profile  
 
PostPosted: Wed Aug 14, 2013 3:30 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6418
Location: WA, USA
Do not use root. Create a different user, like "admin" if you want, and give them the permissions they need.


Top
 Profile  
 
PostPosted: Fri Aug 23, 2013 2:13 am 
Offline
Forum Newbie

Joined: Thu Aug 22, 2013 1:56 am
Posts: 15
You Should check your database credential check $user with root :P


Top
 Profile  
 
PostPosted: Mon Mar 10, 2014 6:30 am 
Offline
Forum Newbie

Joined: Sat Mar 08, 2014 8:39 am
Posts: 11
you need to check the exact mysql account, you can go to http://localhost/phpmyadmin and click to User tab to see account list


Top
 Profile  
 
PostPosted: Mon Sep 08, 2014 5:38 am 
Offline
Forum Newbie

Joined: Mon Sep 08, 2014 5:31 am
Posts: 1
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group