Connecting php to XAMPP
Posted: Tue Aug 13, 2013 1:49 pm
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 !!
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 !!