PHP - Login Scrips Members & How To See If They Are Logged In
Hi, i have a site www.gnetuk.net where people can register and login,. thats all fine but what code can i use on my php pages to see whos logged in im sure its going to be a simple line of code or smthink but i am new to this stuff.
PLEASE HELP <G> Similar Tutorialshey guys, im new to PHP and im trying to use a login script that allows users to register and login to my site from my database. on my login/register pages i get this error Warning: mysql_pconnect() [function.mysql-pconnect]: Unknown MySQL server host 'host' (1) in /home/hullcale/public_html/dbConfig.php on line 12 Error connecting to database. Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'hullcale'@'localhost' (using password: NO) in /home/hullcale/public_html/dbConfig.php on line 20 Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home/hullcale/public_html/dbConfig.php on line 20 it seems like al my problems are from my page dbConfig.php on line 12 and 20, problem is i dont know how to edit them, here is the code from that page... things you may need to know is my databse is called hullcale_database, user is Admin, password is password, as for host im not actually sure where i get this from? any tips?! <? // Replace the variable values below // with your specific database information. $host = "localhost"; $user = "UserName"; $pass = "Password"; $db = "dbName"; // This part sets up the connection to the // database (so you don't need to reopen the connection // again on the same page). $ms = mysql_pconnect(host, $user, $pass); if ( !$ms ) { echo "Error connecting to database.\n"; } // Then you need to make sure the database you want // is selected. mysql_select_db($db); ?> Hi. I'm new to php. I created a register, log in, welcome, and log out page for my site. They are all working accordingly. I'm having one problem that I can't seem to fix. I would like to stay logged in as I navigate other pages of my site. Everytime i click on a link to another page within my site I get logged out. I know this issue might pertain to using session but thats all I was able to find using google search. Can anyone help? Much appreciated. Hi all, I have a problem I am not sure how to sort, hopefully someone here can help. I have a sliding login panel on a website that I am making. Its quite discreet. I have a stripped down version here that you can see: http://mgdesign.hostultra.com/login_test/login_test.php On the page I am making, users with a log in enter their details and will be taken to the restricted page. I would like this sliding panel to be on every page when the user is not logged in. Once they log in from the sliding panel they can still surf around all the main site pages. When they log out the session dies and it reverts to the home page. However, when they are logged in I would like the sliding login panel to disappear from the top of each page. Is there any way I can do this simply? Any help or advice would be greatly appreciated. I have dynamic images that have the "Like" button, it's basically like a wishlist. The way I want it to work is that when a user is not logged in, the 'Like' button will navigate them to a login popup (which I already made). I created a field in "b_users" table as "banned" with default value="no". i.e, all members by default are set to "banned"="no". I was testing this code in my some pages to ban member and prevent access to my pages: $getid="SELECT * from b_users where id='$user_id'"; if($getid[banned]=="yes") { die("<center>You have been banned from posting</center>"); } else { show page Above code is banning all members. But i want to show ban message to members who's "banned" field value is set to "yes" only. How to do that? $_GET["find"] displays all users including the current user. The current user should not be displayed. I would like to display members that are NOT friends with the current user. Do I need to join the tables to make this work? $_GET["add"] inserts "screen_name" into "member and friendwith" Code: [Select] <?php if(isset($_GET["find"])) { $username = $_POST["screen_name"]; $query = "SELECT * FROM users WHERE screen_name LIKE '%$username%'"; $result = mysql_query($query); $exist = mysql_num_rows($result); if($exist=='0') { echo "No match found"; } else { echo "Matches for search: $username<br>"; while($currow = mysql_fetch_array($result)) { ?> <a href="users/member?addfriend=<?php echo $currow['screen_name']; ?>"><img src="avatars/<?php echo $currow["image"]; ?>" ></a> <?php } } } if(isset($_GET["add"])) { $username = $_SESSION["screen_name"]; $friend = $_GET["add"]; $query = "SELECT * FROM friends WHERE member='$username' AND friendwith='$friend'"; $result = mysql_query($query); $exist = mysql_num_rows($result); if($exist=='0') { $query = "INSERT INTO friends(member,friendwith) VALUES('$username','$friend')"; mysql_query($query); echo "$friend is now your friend!"; } else { echo "$friend is already your friend!"; } } ?> Hi guys, Im trying to get my members_profile.php to display the users profile.... I.e members_profile.php?boxerman will display my information. I've been at it for hours but no luck... This is what im trying to code: <?php include ("connect.php") $username = $_GET['username']; $user = mysql_query("SELECT * FROM user WHERE username = '$username'"); $user=mysql_fetch_assoc($user); echo "<h1>User Info</h1>"; echo "<b>Username:".$user['username']."<br>"; echo "<br>"; echo '<form name="backlistfrm" method="post" action="members.php">'; echo '<input type="submit" value="Back to The List">'; echo '</form>'; echo "<br>"; ?> It displays nothing when going to members_profile.php?boxerman Any advice as to why? Regards, B-Man i been working on my view Members page for a while now i can't seem to get it to work right this is how i shows up for me and i want it to show up like this i think it has something to do with the loop, but have no idea how to fix this :S <?php require_once('settings.php'); checkLogin('1 2'); $Members = mysql_query("SELECT * FROM users") or die(mysql_error()); $numRowsMembers = mysql_num_rows($Members); ?> <?php for($count = 1; $count <= $numRowsMembers; $count++) { $name = mysql_fetch_array($Members); ?> <table border=2> <tr><td><img src="<? echo $name['main_P']?>" width="50" height="50"/> <a href="view_profile.php?username=<? echo $name['Username']?>"><? echo $name['Username']?></a> <? $onlinestatus = $name['ON_OFF']; if ( $onlinestatus == OFFLINE ) { echo ""; } else { echo "<font color=green>Online Now!</font>"; } ?> </td></tr></table> <? } ?> Hi Guys, I was wondering how I could wrap my members page so that only 5 members appear at a time and you have to click the next button to go onto the next page. Here is the current code. Code: [Select] $userid = $_SESSION['userid']; $query = "SELECT username, first_name, last_name, password, email, dob, mob, yob, year, gender FROM spotty WHERE user_id = '" . $userid . "'"; $query2 = "SELECT user_id FROM spotty WHERE user_id = '" . $userid . "'"; $result = mysql_query($query) or die('Error Getting Information Requested'); $result2 = mysql_query($query2) or die('Error Getting user_id'); $row = mysql_fetch_array($result); $row2 = mysql_fetch_array($result2); //$result = mysql_query($query); $num = mysql_num_rows($result2); $username = $row['username'] ; if($_SESSION['userid'] == NULL) { echo "Sorry, wrong username or password. You will be redirected in 5 seconds."; echo "<meta http-equiv='refresh' content='7;url=http://www.klueless.net/daisysite'>"; } else { echo "Members."; echo "<br />"; $membsquery="SELECT * FROM spotty WHERE showmem = '0'"; $membs=mysql_query($membsquery); $num=mysql_numrows($membs); $membresult = mysql_result($membs,$i,"user_id"); $useridname = $membresult['username']; echo "<br /> <br />" ; echo "<table border='0' cellspacing='2' cellpadding='2'> <tr> <font face='Comic Sans MS, cursive'>Click on a username to see their profile.</font> <br /> <br /> </tr>"; $i = 0; while ($i < $num) { $f1 = "<font face='Verdana, Geneva, sans-serif'><a href='profile.php?id=" . mysql_result($membs,$i,"user_id") . "'>" . mysql_result($membs,$i,"username") . "</a><br /><br />"; echo "<tr> <td>" . $f1 ."</font></td> </tr> </table>" ; $i++; } } mysql_close() ?> Thanks in advance! Let me make this clear really quick, I am not talking about this forum. Ok, so how do I set up a way that I can make a simple messaging system on my website and make it so that I can have check boxes of who I can send a message to on my website. I have a recipient field and I need to know how I can make it so that only the specific members that are checked will get the message.........does this make sense? Hi i followed a tutorial to create a register, login, members list and member profile pages but when i register, login and go to members list, the page its blank, i viewed the source code for the members page and its clearly trying to show something but i dont know what to do? Can any body help me please. I'm using 3 files to try and mass mail my members, massmail.php massmail-exe.php and elist.php massmail.php <form name="massmail" method="post" action="./massmail-exe.php"> <table width="450px"> <tr> <td valign="top"> <label for="subject">Subject</label> </td> <td valign="top"> <input type="text" name="subject" maxlength="50" size="30" id="subject"> </td> </tr> <tr> <td valign="top"> <label for="message">Email Content</label> </td> <td valign="top"> <textarea name="message" maxlength="9001" cols="100" rows="18" id="message"></textarea> </td> </tr> <tr> <td colspan="2" style="text-align:center"> <input type="submit" value="Submit"> </td> </tr> </table> </form> massmail-exe.php <?php // read the list of emails from the file. $email_list = file("./elist.php"); // count how many emails there are. $total_emails = count($email_list); // go through the list and trim off the newline character. for ($counter=0; $counter<$total_emails; $counter++) { $email_list[$counter] = trim($email_list[$counter]); } // implode the list into a single variable, put commas in, apply as $to value. $to = implode(",",$email_list); if ( mail($to,$_POST["subject"],$_POST["message"]) ) { echo "The email has been sent!"; } else { echo "The email has failed!"; } ?> and elist.php which has the email addresses. What is wrong because every time i try and send it it say query failed. Thanks so much. Hi all, I am trying to write a script where the user can update their details. The html form sends the details across to this php file below. All the php variables echo after the query however the values do not replace the current values in the mysql database. Also for some reason the fname is the only one that changes no matter what the value is. It is entered in to mysql as '0'. I think the problem will be in the php below. As all the information below is echoed correctly, and because the value of 'fname' changes I know the connection is working fine. I guess the error must be in the query I have written, however there is no error that comes up... Hope you can point me in the right direction. Thanks <?php include("../cxn.php"); $fname = $_POST['fname']; $lname = $_POST['lname']; $newemail = $_POST['newemail']; $telephone = $_POST['telephone']; $icao = $_POST['icao']; $newpassword = $_POST['newpassword']; $id = $_POST['id']; $sql = "UPDATE Members SET fname='$fname' AND lname='$lname' AND email='$newemail' AND telephone='$telephone' AND password='$newpassword' AND icao='$icao' WHERE id='$id'"; $result = mysqli_query($cxn,$sql) or die ("Couldn't execute query"); echo "Your new details a <p>"; echo "$fname <br> $lname <br> $newemail <br> $telephone <br> $icao <br> $newpassword"; ?> This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=317715.0 Hi, Im getting better at this php lark! ok so now I have a signup website page, all details get added to the database including an email address, all works fine. now I would like a page, with a simple text box, that when you hit submit, it send the contents of the text box to all email address` in the members table, a really really simple newsletter so to speak. Its purely for my learning curve and Ill set up recapacha on it anyway. but Im getting a bit lost in the code, could someone guide me please? I can grab the contents of the text box like this: $letter = $_POST['letter]; but how do I send to all recipients? $recipient = ("SELECT email FROM members"); thanks Hello to all!
I ask myself the following question: Is there a way that is better to calculate the number of members / guests online Hey i have created the code below attempting to show a specific members details when their username is entered and the submit button is pressed. but when i enter the username all members details are shown. The code i have used is shown below, can anybody help me with the code to just show the single users details. I have attached an image aswell. <?php mysql_connect ("localhost","root",""); mysql_select_db ("test"); $sql = "select * from memberdetails"; $result = mysql_query ($sql); while ($row = mysql_fetch_array($result)) { $username= $row["username"]; $firstname= $row["firstname"]; $surname= $row["surname"]; $dob= $row["dob"]; $totalwins= $row["totalwins"]; $totalloses= $row["totalloses"]; $email= $row["email"]; $country= $row["country"]; $info= $row["info"]; echo "<b><u>Username:</b></u> $username<br>"; echo "<b><u>Firstname:</b></u> $firstname<br>"; echo "<b><u>Surname: </b> </u> $surname<br>"; echo "<b><u>Date of Birth:</b></u> $dob<br>"; echo "<b><u>Total Chess Wins:</b></u> $totalwins<br>"; echo "<b><u>Total Chess loses:</b></u> $totalloses<br>"; echo "<b><u>Email Address: </b></u> $email<br>"; echo "<b><u>Born in: </b></u> $country<br>"; echo "<b><u>Other Details:</b></u> $info<br>"; } ?> Hey everyone! Thanks for taking the time to help. I have two files..a membership area and a commenting section. I am fairly new at these subjects but I am a quick learner. First off, I need help figuring out why my "register.php" in the members area file isn't working properly, everything looks to be ok but maybe I have been working on this too long. Quite frankly I can't check and see if all of the other scripts are correct because I can't get past the "register.php". So if you all wouldn't mind helping me out on this part, I would greatly appreciate it Secondly, I have a commenting section and in the "demo.php", there is a warning that appears as follows: "Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\Program Files (x86)\EasyPHP-5.3.8.1\www\comments\demo.php on line 17 " If someone could tell me what is missing or help me figure out what to do in simple terms, I would greatly appreciate that as well. Thanks! Gene [attachment deleted by admin] Im creating a token system where if a user uploads notes they get tokens and can download other peoples notes. My problem is I am not sure where to store the information for who has bought the note for future download. Should I store the information in the database under the table that looks after the notes, in its own table, or in a file that has arrays of the Note names and the users who are allowed to download it. I figured the best way would to have it in the db table that looks after the users but im not sure how I would get about making it so that every time the user bought another note I didnt have to add a new field. ok i have been trying for over a week now, and i just relearning php again after a few years of being lazy. lol here is a code snippet. Quote //prep the members $myFile2 = "members.txt"; $fh2 = fopen($myFile2, 'r'); $theData2 = fread($fh2, filesize($myFile2)); fclose($fh2); //echo $theData2; //grab the stats! $url = 'http://link'; $postdata = 'players='.$theData2.'&fields=all'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata); $data = curl_exec($ch); curl_close($ch); $data = json_decode($data,true); the orininal code Quote //prep the members $members = "member,member1,member two,member blue"; //grab the stats! $url = 'http://link'; $postdata = 'players='.$members.'&fields=all'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata); $data = curl_exec($ch); curl_close($ch); $data = json_decode($data,true); now the problium i am having is that with the original way, listing the members indevidualy is not the way i would like it, it would be easyer if it was in .txt form so i can add top it easyer. Also i have 300 people to add and the string doesnt seem to like that many people in it.....so i made a txt file, and it all works except that when i load the page it does not display the members stats from the external link. each players stats gets posted on the page and sorted who is ranked highest. echo works for echoing the contents of the file. however thats usless to me as i want the contents of the file to work like the orininal code. sorry if its confusing.... basicaly there is data from the link for each player asociated with there name. which is seperated by a , in the code. so each time a , is reached the code repeats its self posting each player till there are no more to post. the string is to short for me or just seems to not work with 300 people. i need it to read the external .txt file or something simular and work in the same mannor. |