views:

13

answers:

0

Good Evening All,

I'm very new to PDO prepared statements and need some guidance/gentle nudges. I've created the following MySQL stored procedure:

-- --------------------------------------------------------------------------------
-- Routine DDL
-- --------------------------------------------------------------------------------
DELIMITER $$

CREATE DEFINER=`root`@`%` PROCEDURE `RegInsert`(
IN p_regid int,
IN p_username VARCHAR(45),
IN p_password VARCHAR(45),
IN p_confpassword VARCHAR(45),
IN p_status INT(1),
IN p_salutation VARCHAR(45),
IN p_firstname VARCHAR(45),
IN p_lastname VARCHAR(45),
IN p_jobtitle VARCHAR(45),
IN p_telephone VARCHAR(45),
IN p_companyname VARCHAR(45),
IN p_industry VARCHAR(45),
IN p_address VARCHAR(45),
IN p_city VARCHAR(45),
IN p_state VARCHAR(45),
IN p_country VARCHAR(45),
IN p_postalcode VARCHAR(45),
IN p_regtype VARCHAR(45),
IN p_interest VARCHAR(45),
IN p_hdsprovider VARCHAR(45)
)
BEGIN
Insert into regdata(
RegID,
UserName,
Password,
Confpassword,
Status,
Salutation,
FirstName,
LastName,
JobTitle,
Telephone,
Companyname,
Industry,
Address,
City,
Country,
State,
PostalCode,
RegType,
Interests,
HDSprovider
)
values(
p_regid,
p_username,
p_password,
p_confpassword,
p_status,
p_salutation,
p_firstname,
p_lastname,
p_jobtitle,
p_telephone,
p_companyname,
p_industry,
p_address,
p_city,
p_country,
p_state,
p_postalcode,
p_regtype,
p_interest,
p_hdsprovider
);
END

In reading the documentation on PDO, I understand that the following statement is used to open the connection and the try catch block sets the parameters. That's where I'm getting confused. Here's my code block thus far:

<?php
require once ("/home/somedir/pdo_connect.php")
try{
$dbh=pdo_connect.php();
$stmt = $dbh->prepare("CALL RegInsert(?)");
$stmt->bindParam
}
catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
?>

Questions:
1. What is the correct syntax for associating my procedure input parameters with my PHP form variables? Is it something like:

$_Post['salutation'] = p_salutation
  1. Reginsert.php contains the above PDO statements. How do I call it from my submit button on the form?

  2. Do you suggest creating a separate file and container function for the confirmation email? If so, how do I trigger that file to run after reginsert.php runs without errors?

Thanks so much for helping this sleep-deprived newbie. It's much appreciated!!

EDIT:

Here's the revised code for reginsert.php. When I provide valid form data and press submit, a record is not inserted into the database. Can you steer me in the right direction?

<?php
require once ("/home/mydir/pdo_connect.php")
try{
$dbh=pdo_connect.php();
$stmt = $dbh->prepare('CALL RegInsert(?)');
$stmt->bindParam(':p_username',$email_address,PDO::PARAM_STR,45);
$stmt->bindParam(':p_password',$create_password,PDO::PARAM_STR,45);
$stmt->bindParam(':p_confpassword',$confirm_password,PDO::PARAM_STR,45);
$stmt->bindParam(':p_salutation',$salutation2,PDO::PARAM_STR,45);
$stmt->bindParam(':p_firstname',$first_name,PDO::PARAM_STR,45);  
$stmt->bindParam(':p_lastname',$last_name,PDO::PARAM_STR,45);
$stmt->bindParam(':p_jobtitle',$job_title,PDO::PARAM_STR,45);
$stmt->bindParam(':p_telephone',$telephone,PDO::PARAM_STR,45);
$stmt->bindParam(':p_companyname',$company_name,PDO::PARAM_STR,45);
$stmt->bindParam(':p_industry',$industry,PDO::PARAM_STR,45);
$stmt->bindParam(':p_address',$address,PDO::PARAM_STR,45);  
$stmt->bindParam(':p_city',$city,PDO::PARAM_STR,45);
$stmt->bindParam(':p_state',$state,PDO::PARAM_STR,45);
$stmt->bindParam(':p_country',$country,PDO::PARAM_STR,45);
$stmt->bindParam(':p_postalcode',$postal_code,PDO::PARAM_STR,45);
$stmt->bindParam(':p_regtype',$partner_customer_other,PDO::PARAM_STR,45);
$stmt->bindParam(':p_interest',$interests,PDO::PARAM_STR,45);
$stmt->bindParam(':p_hdsprovider',$provider_partner,PDO::PARAM_STR,45);
$stmt->bindParam(':p_passwordremindquestion',$password_reminder_question,PDO::PARAM_STR,45);
$stmt->bindParam(':p_passwordremindanswer',$password_reminder_answer,PDO::PARAM_STR,45);
$stmt->execute();
}
catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
?>