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);

?>

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;
    }
  }
}

?>

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.