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
https://forums.phpfreaks.com/topic/135605-mysql-row-problem/
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
https://forums.phpfreaks.com/topic/135605-mysql-row-problem/#findComment-706563
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
https://forums.phpfreaks.com/topic/135605-mysql-row-problem/#findComment-706729
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.