It’s possible.
Btw, I changed $con to $pdoConn when I would do the tests (as I didn’t know if it would have had any actual impact in relation to db.php). But, I revert it back to $con afterwards. Lemme know is if I should change it permanently (assuming it has an actual impact with your code. I was unsure)
I also deleted all the coding that was related to my picture uploads (which shouldn’t in any way affect the rest of the code).
[php]<?php
include (‘config.php’);
// The following checks to see whether PDO is enabled or not.
/*if (!defined(‘PDO::ATTR_DRIVER_NAME’)) {
echo ‘PDO unavailable’;
}
elseif (defined(‘PDO::ATTR_DRIVER_NAME’)) {
echo ‘PDO available’;
}
*/
/*** hostname ***/
//$hostname = ‘127.0.0.1’;
//$hostname = ‘localhost’;
/*** username /
//$username = '****’;
/*** password /
//$password = '****’;
/*** database name /
//$db = '****’;
// verifies there is actually a pass
//var_dump(DB_PASS);
define(‘DB_HOST’, ‘127.0.0.1’);
define(‘DB_USER’, ‘’);
define(‘DB_PASS’, '’);
define(‘DB_NAME’, ‘*******’);
require_once (‘db.php’);
//This gets all the other information from the form
// mysql_real_escape_string to escape sepcial character, a.k.a. some forms of sql injections
$compagnie=mysql_real_escape_string($_POST[‘company’]);
$telephone=mysql_real_escape_string($_POST[‘phone’]);
$site_web=mysql_real_escape_string($_POST[‘website’]);
$texte_fr=mysql_real_escape_string($_POST[‘messagefr’]);
$texte_en=mysql_real_escape_string($_POST[‘messageen’]);
$categories=mysql_real_escape_string($_POST[‘categories’]);
$profil_exposant=mysql_real_escape_string($_POST[‘profession’]);
$stands_du_manufacturier=mysql_real_escape_string($_POST[‘manufacturiers_stand’]);
$pourcentage_quebec=mysql_real_escape_string($_POST[‘percent_quebec’]);
$pourcentage_canada=mysql_real_escape_string($_POST[‘percent_canada’]);
$pourcentage_usa=mysql_real_escape_string($_POST[‘percent_usa’]);
$pourcentage_autre=mysql_real_escape_string($_POST[‘percent_autre’]);
$exporte=mysql_real_escape_string($_POST[‘bt_export’]);
$exporte_souhaite=mysql_real_escape_string($_POST[‘bt_export_souhaite’]);
$produits_vert=mysql_real_escape_string($_POST[‘bt_prod_verts’]);
$nouveau_produits=mysql_real_escape_string($_POST[‘bt_new_prod’]);
$nom=mysql_real_escape_string($_POST[‘name’]);
$courriel=mysql_real_escape_string($_POST[‘email’]);
$telephone_ressource=mysql_real_escape_string($_POST[‘resource_phone’]);
$personne_ressource_c_toi=mysql_real_escape_string($_POST[‘personne_ressource’]);
$autre_personne_ressource=mysql_real_escape_string($_POST[‘backup_name’]);
$autre_courriel=mysql_real_escape_string($_POST[‘backup_email’]);
$autre_telephone=mysql_real_escape_string($_POST[‘backup_phone’]);
if(count($cats) > 0)
{
$str = implode(",", $cats);
}
// implodes makes the values as a string!
// in the values part when inserting it, you will have to use ‘$str’ instead of $_POST[$cats];
$cats = array();
if($_SERVER[‘REQUEST_METHOD’] == ‘POST’) {
if(isset($_POST[‘cats’])) {
$cats = implode(",", $_POST[‘cats’] );
}
$categories= $_POST[‘categories’];
$str = $categories . ": " . $cats;
//echo $str;
}
try {
$con = new PDO(“mysql:host=$hostname;dbname=$db”, $username, $password);
/*** echo a message saying we have connected ***/
//echo ‘Connected to database
’;
$stmt = $con->prepare(“INSERT INTO form_corpo_test VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)”);
if (!$stmt) {
$error = $stmt->errorInfo();
echo 'PDO error: ’ . $error[2] . ‘(’ . $stmt->errorCode() . ‘)’;
} else {
$stmt->execute(array(
$_POST[‘company’], $_POST[‘phone’], $_POST[‘website’], $_POST[‘messagefr’], $_POST[‘messageen’], $str, $_POST[‘profession’], $_POST[‘manufacturiers_stand’], $_POST[‘percent_quebec’], $_POST[‘percent_canada’], $_POST[‘percent_usa’], $_POST[‘percent_autre’], $_POST[‘bt_export’], $_POST[‘bt_export_souhaite’], $_POST[‘bt_prod_verts’], $_POST[‘bt_new_prod’], $_POST[‘name’], $_POST[‘email’], $_POST[‘resource_phone’], $_POST[‘personne_ressource’], $_POST[‘backup_name’], $_POST[‘backup_email’], $_POST[‘backup_phone’]
));
if (!$stmt) {
$error = $stmt->errorInfo();
echo 'PDO error: ' . $error[2] . '(' . $stmt->errorCode() . ')';
} else {
echo 'Insert OK';
}
}
/*** close the database connection ***/
$con = null;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>[/php]