Jump to content

Recommended Posts

I am coding a php website and i have everything ready to start on the user interface, but now it wont get the data from the login to get data from the database.

I added some debugging code in to see if it even gets a session and it doesn't even get one, can someone please help me and tell me what i am doing wrong?.

 

My login code:

<?php

include('/home/sites/******/MasterConfig/Config.php'); 
$tbl_name='U_members'; // Table name </p>
session_start();
ob_start();

// Connect to server and select databse.
mysql_select_db("$db_name")or die("cannot select DB");

// Define $myusername and $mypassword 
$myusername=$_POST['MYusername']; 
$rawpassword=$_POST['MYpassword'];
$mypassword=md5($rawpassword);
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE Username='$myusername' and Password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
$_SESSION['loggedin'] = true;
$_SESSION['username'] = $_POST['MYusername'];
header("location:/welcome.php");
}
else {
echo "Wrong Username or Password";
}
ob_end_flush();
?>

 

Welcome.php:

<?php
include('/home/sites/*********MasterConfig/Config.php');
$tbl_name = "U_items"; // Table name </p>
ob_start();

?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php
ob_start();
session_start();
?>
<meta charset="utf-8">

<link rel="stylesheet" href="css/all.css">

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.easing.1.3.js"></script>
<script type="text/javascript" src="js/jquery.quicksand.js"></script>
<script type="text/javascript" src="js/main.js"></script>

<title>Product Filter</title>
</head>

<body>
<?php
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true) {

}
else {
mysql_close($_SESSION['connect']);
header("location:/index.php");
}
?>
<h1> Welcome <?php $_SESSION['username']; ?> </h1>
<div id="container">
  <ul id="filterOptions">
    <li class="active"><a href="#" class="all">All my products</a></li>
    <li><a href="#" class="Car">My cars</a></li>
    <li><a href="#" class="champ">My motorbikes</a></li>
    <li><a href="#" class="league1">My ECO</a></li>
    <li><a href="#" class="league2">My Art</a></li>
  </ul>
  
  <ul class="ourHolder">
    <li class="item" data-id="id-1" data-type="Car">
    <?php
mysql_select_db("$db_name")or die("cannot select DB");
$SQL = mysql_query('SELECT * FROM ' + $tbl_name + ' WHERE Owner = ' + $_SESSION['username']);
while($row = mysql_fetch_row($SQL));
$id=$row['ID'];
$photo=$row['PicLink'];
$ItemName=$row['Name'];

if(isset($_SESSION['userName']))
{
  print "Your session username: ".$_SESSION['username']. "<br>";
}
else
{
  print "Session does not exist";
}
?>
    <img src="<?php $Photo ?>" alt="<?php $ItemName ?>" />
    <h3> <?php $ItemName ?></h3>
    
    </li>
    </li>    
  </ul>
</div>

</body>
</html>

 

 

Link to comment
https://forums.phpfreaks.com/topic/249477-cant-get-user-information-after-login/
Share on other sites

now if i would remove the critics from this post i would have 0 replys, as a mod you 2 should be ashamed for only posting critics while knowing in your head i'm still learning if you would have send a good reply then you would have told me what the problem was and you would have told me that some parts are out of date and where i can find better resources.

 

the only thing that you 2 mods did was boost your own ego, i would suggest going to a beginners course and giving those answers to their first project if you want to feel all high and mighty about your coding knowledge, and i'm probably going to get banned for this post because i am telling 2 mods this but if i get banned i wont even care and just look for a better forum that has good people on it that know how to help and not just boost their own ego witch is very sad.

 

and i bet you are saying to your self "what a noob" or something, but if you do think something like that then more shame on you because if you did a good job as a mod your answer would have contained the following:

 

- direct answer with my question

- what part i need to change so my code is uptodate

 

in stead you're code contains the following:

- talking trash

- no help in anyway (WITH EXCETION TO THE FIRST REPLY witch actually contained a link with help and thank you for that)

This forum is for PHP programmers looking to get help with their own code

 

He's under the assumption you don't understand your code. For the most part, you've pretty much copied it. The issue with this is you aren't getting help, you're getting it fixed. The issue with that is, if you want to change basic functionality or something goes wrong, you have no idea what to do and you'll come back here expecting someone to fix it again.

 

See my signature for a good article and some code for a proper user/password system.

 

This is not a good beginner program though. User authentication and stateful design through sessions can become quite complex, and adds a new layer of potential quirks. I suggest starting elsewhere.

"Hi, my name is tinytime.  I'm having a problem with my code, please tell me what I've done wrong without making any negative comments."

 

Screw that.  Go buy a book.  You're working off a piece of code from SEVEN YEARS AGO.  The functions you're using are OFFICIALLY DEPRECATED. 

 

If you think you can change our behavior as a new user then shame on you, because if you were doing your job as a random jerk who's asking us to do things for him for free then your question would have contained:

- The steps you had already tried to debug this on your own

- Complete sentences

- Small snippets of code instead of entire pages

- Proper code formatting

 

We are no magic.  We can't look at your 100 lines of poorly written code which uses poor practices and functions that are known to be bad and tell you exactly which lines are wrong.  I'll tell you which lines are wrong:  ALL OF THEM.  Rewrite the whole thing and do it right.

 

You're an ass, get out of here. 

 

Thread closed.

Guest
This topic is now 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.