Jump to content

mysql $row problem


SN1P3R_85

Recommended Posts

Hi, I have a script where people can register on my site, and it works, but there is a problem with it. If the register goes through, it is supposed to log them on as well. On my site logging on consists of three parts, username, userlevel, and validate. I set three php sessions with these values. It sets the username and validate fine, but it won't set userlevel. Userlevel is in the same table as username, so I don't know why it won't work. However, when i use the login script, it sets it.

 

$query = "INSERT INTO `users` (Username, Password, Userlevel, Email)
VALUES ('$username', '$password', '$usr_level', '$email')";

$result = mysql_query($query);

if ($result)
{
	$_SESSION['username'] = $row['Username'];
	$_SESSION['userlevel'] = $row['Userlevel'];
	$_SESSION['uservalid'] = true;
	echo "registration successful, you are a " . $row['Userlevel'] . ".";
}

Link to comment
Share on other sites

<?php
$query = "INSERT INTO `users` (Username, Password, Userlevel, Email)
   VALUES ('$username', '$password', '$usr_level', '$email')";

   $result = mysql_query($query);

   if ($result)
   {
      $row = mysql_fetch_assoc($result);
      $_SESSION['username'] = $row['Username'];
      $_SESSION['userlevel'] = $row['Userlevel'];
      $_SESSION['uservalid'] = true;
      echo "registration successful, you are a " . $row['Userlevel'] . ".";
   }
?>

Link to comment
Share on other sites

Please read a basic mysql book or a mysql tutorial before attempting to use mysql. Fetching a row of data from the result set before using that data is basic understanding of how to use a database.

 

And please learn php, develop php code, and debug php code on a development system with error_reporting set to E_ALL and display_errors set to ON to get php to help you. The missing $row[..] variables would have triggered error messages to help you discover that there is no code setting them.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.