PDA

View Full Version : mysql insert problem


zoliky
07-20-06, 03:59 PM
// Check if user exist in db
$find_username = mysql_query("SELECT user_id,username FROM register WHERE username = '".varCheck($_POST['username'])."'");
$duplicate_username = mysql_num_rows($find_username);
$uid = mysql_fetch_array($find_username);

// Check if email exist in db
$find_email = mysql_query("SELECT email FROM register WHERE email = '".varCheck($_POST['email'])."'");
$duplicate_email = mysql_num_rows($find_email);

if (isset ($_POST['submit'])) {

$problem = FALSE;

if (empty ($_POST['username'])) {
$problem['username'] = TRUE;
print "<p>Please type a username</p>\n";
}

if ( ($duplicate_username > 0 )) {
$problem['username'] = TRUE;
print "<p>The username already exist in database!</p>\n";
}

if ( ($duplicate_email > 0 )) {
$problem['email'] = TRUE;
print "<p>The email address already exist in database!</p>\n";
}

if (!$problem) {
if (($duplicate_username == 0 ) && ($duplicate_email == 0)) {
mysql_query ("INSERT INTO register (user_id, username, password, email, validate, forgetpwd, date_entered) VALUES (0, '".varCheck($_POST['username'])."', '".crypt($_POST['password'],"{$_POST['username']}")."', '".varCheck($_POST['email'])."', '".sha1($_POST['username']. time())."', '0', NOW())") or die (mysql_error());
mysql_query ("INSERT INTO user2groups (uid) VALUES ('".$uid['user_id']."')");


I want to insert the added user "user_id" to user2groups table, the following line do this :


mysql_query ("INSERT INTO user2groups (uid) VALUES ('".$uid['user_id']."')");


But I don't get the user_id value :(

Any idea or suggestion ?