Jump to content

PDO create (Insert) question


fullyloaded

Recommended Posts

Hey,

I was wondering if its ok to have my code the way i have it below, 2 inserts one after the other? or is there a proper way of doing this any help would be great thanks.

$query = "INSERT INTO users (user,pass,salt,email,firstname,lastname,gender,country,actnum
) VALUES (:user,:pass,:salt,:email,:firstname,:lastname,:gender,:country,:0)";
$salt = dechex(mt_rand(0, 2147483647)) . dechex(mt_rand(0, 2147483647));
$pass = hash('sha256', $_POST['pass'] . $salt);
$query_params = array(
            ':user' => $_POST['user'],
            ':pass' => $pass,
            ':salt' => $salt,
            ':email' => $email,
            ':firstname' => $firstname,
            ':lastname' => $lastname,
            ':gender' => $gender,
            ':country' => $country,
            ':actnum' => $actnum
);
try
{
      $stmt = $db->prepare($query);
      $result = $stmt->execute($query_params);
}
catch(PDOException $ex)
{
     die("Failed to run query: " . $ex->getMessage());
}
$query = "INSERT INTO users_msg_sent (user,emails,bdaygreetings,totalsent
) VALUES (:user,:0,:0,:0)";
$query_params = array(
           ':user' => $_POST['user'],
           ':emails' => $emails,
           ':bdaygreetings' => $bdaygreetings,
           ':totalsent' => $totalsent
);
try
{
       $stmt = $db->prepare($query);
       $result = $stmt->execute($query_params);
}
catch(PDOException $ex)
{
      die("Failed to run query: " . $ex->getMessage());
}

 

Link to comment
https://forums.phpfreaks.com/topic/266822-pdo-create-insert-question/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.