I have a paid website and after the transaction is complete i have a page with posted variables of the user that just paid. Want to create a script to take those posted variables and create a new user in the database.
have this so far but does not work
<?
$_POST['customer_fn'];
$_POST['customer_ln'];
$_POST['email'];
$_POST['username'];
$_POST['password'];
$password = $_POST['password'];
$con = mysql_connect("-----","-----","-------");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("deyette_gallery", $con);
mysql_query("INSERT INTO `deyette_gallery`.`deyette_gallery_User` (g_id, g_userName, g_fullName, g_hashedPassword, g_email, g_language, g_locked )
VALUES ('', '$_POST[username]','$_POST[customer_fn]$_POST[customer_ln]', '$password', '$_POST[email]', '$_POST[en_US]', '0')");
mysql_close($con);
?>
Table structure for table deyette_gallery_User
Field Type Null Default
g_id int(11) No
g_userName varchar(32) No
g_fullName varchar(128) Yes NULL
g_hashedPassword varchar(128) Yes NULL
g_email varchar(255) Yes NULL
g_language varchar(128) Yes NULL
g_locked int(1) Yes 0
Posts: 7994
That's a G2 table. Moving this to the G2 forums.
---
Problems? Check gallery3/var/logs
bugs/feature req's | upgrade to the latest code | use git
Posts: 8339
You should use the gallery framework to create the user, other things need to happen besides the DB entry.
pass your user $_POST for $args, but hash your pass first.
/* Connect to Gallery */ require_once ('/full/system/path/to/gallery2/embed.php'); $ret = GalleryEmbed::init(array('fullInit'=>true)); if ($ret) { echo 'GalleryEmbed::init failed, here is the error message: '.$ret->getAsHtml(); exit; } GalleryEmbed::done(); function createUser($args) { global $gallery; list($ret, $user) = GalleryCoreApi::newFactoryInstance('GalleryEntity', 'GalleryUser'); if ($ret) { return $ret; } if (!isset($user)) { return GalleryCoreApi::error(ERROR_MISSING_OBJECT); } $ret = $user->create($args['username']); if ($ret) { return $ret; } // You'll already have the password, but hash it up first. $ret = setUserData($user, $args); if ($ret) { return $ret; } $ret = $user->save(); if ($ret) { return $ret; } return null; } function setUserData(&$user, $args, $create=false) { global $gallery; if (!empty($args['password'])) { $user->changePassword($args['password']); } else if (!empty($args['hashedpassword'])) { if (!isset($args['hashmethod']) || !in_array($args['hashmethod'], array('md5', 'phpass'))) { return GalleryCoreApi::error(ERROR_BAD_PARAMETER, __FILE__, __LINE__, 'hashmethod must be either md5 or phpass'); } $user->setHashedPassword($args['hashedpassword']); } else if ($create) { /* Create a random password */ $user->changePassword('G' . rand(100000,999999) . '2'); } if (isset($args['username'])) { $user->setUserName($args['username']); } if (isset($args['email'])) { $user->setEmail($args['email']); } if (isset($args['fullname'])) { $user->setFullName($args['fullname']); } if (isset($args['language'])) { list ($languageCode) = GalleryTranslator::getSupportedLanguageCode($args['language']); $user->setLanguage($languageCode); } if (isset($args['creationtimestamp'])) { $user->setCreationTimestamp($args['creationtimestamp']); } }-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2