atrum Posted February 26, 2009 Share Posted February 26, 2009 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 https://forums.phpfreaks.com/topic/146981-unable-to-pull-data-and-use-in-a-_session/ Share on other sites More sharing options...
trq Posted February 26, 2009 Share Posted February 26, 2009 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 https://forums.phpfreaks.com/topic/146981-unable-to-pull-data-and-use-in-a-_session/#findComment-771672 Share on other sites More sharing options...
atrum Posted February 26, 2009 Author Share Posted February 26, 2009 haha, omg! I must have been very tired, thanks for the assist. Link to comment https://forums.phpfreaks.com/topic/146981-unable-to-pull-data-and-use-in-a-_session/#findComment-771975 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.