PHP Newbie

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
artisticre
New php-forum User
New php-forum User
Posts: 1
Joined: Tue Feb 28, 2017 11:02 am

Tue Feb 28, 2017 12:09 pm

I need help creating PHP inserts for this. The form has multiple entries. Attached is my database structure. Is anyone willing to get me headed in the right direction?
database.png
database.png (34.68 KiB) Viewed 1372 times

chorn
php-forum Fan User
php-forum Fan User
Posts: 562
Joined: Fri Apr 01, 2016 2:18 am

Tue Feb 28, 2017 10:41 pm

post code of your database connection (PDO recommended).

boxfly
New php-forum User
New php-forum User
Posts: 9
Joined: Mon Mar 06, 2017 5:17 am

Mon Mar 06, 2017 6:08 am

Do you want to use PDO to insert data in your database?

Here is an example:

Code: Select all

$sql = $dataBase->prepare('INSERT INTO user(email,
                                            firstname,
                                            lastname,
                                            lang) 
                                   VALUES (:email,
                                           :firstname,
                                           :lastname,
                                           :lang)');

$sql->execute(array('email'     => $_POST['Email'],
                    'firstname' => $_POST['Firstname'],
                    'lastname'  => $_POST['Lastname'],
                    'lang'      => $_POST['Lang'])
Last edited by boxfly on Tue Mar 07, 2017 1:34 am, edited 4 times in total.

boxfly
New php-forum User
New php-forum User
Posts: 9
Joined: Mon Mar 06, 2017 5:17 am

Mon Mar 06, 2017 6:11 am

And of course you have to connect to your database before. Here is an example of connecting to a mysql database:

Code: Select all

$dataBase= new PDO('mysql:host='.$config['DatabaseDomain'].';dbname='.$config['DatabaseName'].';charset=utf8', $config['DatabaseUser'], $config['DatabasePassword'], array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); 
With $config['DatabaseDomain'], $config['DatabaseName'], $config['DatabaseUser'] and $config['DatabasePassword'] as variables to connect to your database.

Post Reply