Jump to content

CyRus2273

New Members
  • Posts

    6
  • Joined

  • Last visited

    Never

Everything posted by CyRus2273

  1. Thanks for all the answers, but I must be stupid. I can't figure this out. The three pages I have in this loop are: login.html (with the form), checklogin.php (where the data from the form is send to and checked against the database) and members.php (where the user is send to if login is correct - otherwise user is send back to login.html). I tried adding the code that you suggested but quite honestly I didn't know what segments to take out and replace with your code. I really appreciate your help guys but I really suck at php so please bare with me If you guys wouldn't mind if would be easier for me to see my own code altered instead of correct code posted as I don't know where to put it in Thanks again, and sorry for not understanding
  2. Thanks, but I'm pretty lost on the whole register thing Given the code I provided how would I go about implementing it there. The thing is this. I have one page with a form requiring username and password that when submitted posts the data to checklogin.php. The username and password is then checked against my database and if correct the user is redirected to the member site, where the first line of code is: <? session_start(); if(!session_is_registered(myusername)){ header("location:login.html"); } ?> Following this php code is a whole bunch of html showing the actual member site. Inside this html I have then added: <div id='splitter2'> <?php echo "Hello " . $myusername; ?> </div> , which at the current time prints out: Hello test123 (e.g.). I would then like it to instead of printing out the username which is usually something corny I would like it to print out Hello John (e.g.), where John in the database is associated with the username test123.
  3. In my database I have username, password, email and real name. I assume I have to register username and password in order to verify the user is logged in. Furthermore I would like to register real name so that I can print out: Hello "Real name".
  4. How would I go about this? I'm pretty new to html and php so sorry if I ask stupid questions
  5. Thanks for the reply. I actually figured it out by adding this block of code: <?php echo "Hello " . $myusername; ?> , so that was basically the same you suggested. My next question is then, how do I register something in the session that is not contained in the form. Meaning that in my database I have username, password and real name. It would obviously look better if I could get the code to print out "Hello "Real name"". I hope it makes sense, and again, thanks for your answer.
  6. Hi guys I am new to PHP and need som help. I have set up a site that allows a user to log in through a simple form where the data is then send to checklogin.php. Here the data is checked up against my sql database and if the login is correct the user is transfered to the "secret" members only site. All this works fine. My question is then, how do I get the members site to greet the member with "Hello 'username'"; of course where the username changes depending on the login. This is the part where the username and password is checked: <?php $host="mydbb10.surftown.dk"; // Host name $username="****"; // Mysql username $password="****"; // Mysql password $db_name="****"; // Database name $tbl_name="members"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // username and password sent from form $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // 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 "korrekt.php" session_register("myusername"); session_register("mypassword"); echo "Tak fordi du loggede ind<br>Redirecter..."; header("location: ../forhandlerservice.php"); } else { echo "Forkert brugernavn eller password"; header("location: ../loginfejl.html"); } ?> and this is the first line of code on the members site: <? session_start(); if(!session_is_registered(myusername)){ header("location:login.html"); } ?> Sorry if I provided to much code, just want to make sure that I don't forget anything. Any help is appreciated. Thank you
×
×
  • 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.