Problem with a PHP code existing

Hello all ! I’m new here so i will try to be clear in what I have to do.

I am currently studying in an engineering school and I have to use existing php and explain what each part of the line of codes corresponds to.

So I found a code on the internet, but I can not make it work on my computer, it is a game called ‘Drafts’ and which is coded in php.

I can not run the code on my computer at all and I think I have a problem with adding the database, knowing that I am using the xammp software

Here is the code in question:
This is the PHP Code :

This is my CSS :

table {`
border-collapse: collapse
table td {
width: 60px;
height: 60px.

And this is my table :

– Structure of the table jeu_dames_plateau

CREATE TABLE IF NOT EXISTS jeu_dames_plateau (
ID tinyint(3) unsigned NOT NULL,
x tinyint(2) unsigned NOT NULL,
y tinyint(2) unsigned NOT NULL,
fond tinyint(1) unsigned NOT NULL,
pion tinyint(2) unsigned NOT NULL,

– Content of the table jeu_dames_plateau

INSERT INTO jeu_dames_plateau (ID, x, y, fond, pion) VALUES
(1, 1, 1, 0, 20),
(2, 1, 2, 1, 0),
(3, 1, 3, 0, 20),
(4, 1, 4, 1, 0),
(5, 1, 5, 0, 20),
(6, 1, 6, 1, 0),
(7, 1, 7, 0, 20),
(8, 1, 8, 1, 0),
(9, 1, 9, 0, 20),
(10, 1, 10, 1, 0),
(11, 2, 1, 1, 0),
(12, 2, 2, 0, 20),
(13, 2, 3, 1, 0),
(14, 2, 4, 0, 20),
(15, 2, 5, 1, 0),
(16, 2, 6, 0, 20),
(17, 2, 7, 1, 0),
(18, 2, 8, 0, 20),
(19, 2, 9, 1, 0),

(I’m sorry for the pictures but I did not know how to show you the code in the best way possible)

So my question is now:

Does this code seem to you to be right and functional, and does my concern really come from the fact that I can not connect to the database?

I hope I have been clear and thank you for your time !

Here is the picture of the table because i think it will be more clear for you : Capture

It would be more helpful if you post actual error messages, and on your developing machine you should enable error reporting on top of your script:

ini_set('display_errors', TRUE);


Well, this is the error message i get, so now i’m pretty sure that i have a probleme with my database. Since i’m using xampp, i have PHPmyAdmin. So i guess i need to replace line 3 by a code which will connect my php code with the database right ?

$BDD has to be some kind of database connection, yes, looks like it could be PDO.

First, you have to create a database myDB and then the table ‘jeu_dames_plateau’ and by guessing that you know how to create tables in your local host (XAMPP for example) you should do the next:

By reading the error log carefully you will find that BDD variable is undefined, and that is because you haven’t established the connection with the database. To establish a connection add following lines just before $req = BDD->query(‘SELECT * FROM jeu_dames_plateau ORDER BY x, y’); in your PHP code:

$host = "localhost";
$username = "root";
$password = "";
$database = "myDB";
try {
    $BDD= new PDO("mysql:host=$host;dbname=$database", $username, $password);
    // set the PDO error mode to exception
    echo "Connected successfully";
catch(PDOException $e)
    echo "Connection failed: " . $e->getMessage();

If you have problems setting up your localhost, start a new thread and I will help you there.
You also have to be aware that querying data must be secured by using prepared statements either using mysqli or PDO.

Sponsor our Newsletter | Privacy Policy | Terms of Service