Jump to content

Unable to pull data and use in a $_SESSION


atrum

Recommended Posts

Hello all,

 

been trying to grab data from my database and use it as a value for a session. I can get it to display the data in a table without using a WHERE clause, and with out the if statement, but with those two added, I get just a blank screen with out any error.

 

Would someone mind taking a look at this code, because I can't seem to find the problem.

 

 

Thanks in advance.

 

 

 

 

 

<?php
session_start();
ini_set('display_errors','On');

include("constr.php");
$passwordHash = sha1($_POST['password']);


$username ="$_POST[username]";
$sqlu ="SELECT * FROM ts_membership WHERE mUserName='$username' AND mPassword='$passwordHash'";
$result = mysql_query($sqlu) or die (mysql_error());
if (!mysql_query($sqlu,$sqlcon))

{
die('Error: unable to connect (login.php):' . mysql_error());
}
else
while($row = mysql_fetch_array($result))
{
$_SESSION['user']=$row['mUserName'];
}
//header('Location: ./home.php');

mysql_close($sqlcon);

?>

Link to comment
Share on other sites

Not sure why but you where executing your query twice. There where a few other messy areas as well that I've cleaned up.

 

<?php

if (isset($_POST['username']) && isset($_POST['password'])) {

  session_start();

  include "constr.php";

  $passwordHash = sha1($_POST['password']);
  $username = $_POST['username'];

  $sql ="SELECT * FROM ts_membership WHERE mUserName='$username' AND mPassword='$passwordHash'";
  if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
      $_SESSION['user'] = $username;
    }
  }
}

?>

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.