Jump to content

dean7

Members
  • Posts

    309
  • Joined

  • Last visited

Everything posted by dean7

  1. Hey guys, I'm attempting to code a simple find user script for my website in which I cannot get my head around why my data in my while loop isn't displaying. I keep having breaks from coding as I only do it for something todo when I have time so this website wont be going live its just for me to make so if its unsecure its no big deal. if (isset($_POST['user_button']) && ($_POST['theusername'])){ $theusername = $_POST['theusername']; $query11 = "SELECT * FROM UsersRegTable WHERE username LIKE ':theusername'";$select = $db->prepare($query11);$select->bindValue(":theusername", "%".$theusername."%"); $select->execute();$total = count($select); echo $total; // always finds 1 echo "</table><br /><table width='25%' border='1' align='center' cellpadding='0' cellspacing='0' class='tableborder'><tr><td colspan='2' class='header' align='center'>Users:</td></tr><tr><td class='forum' align='center'>Username:</td><td class='forum' align='center'>Rank:</td></tr>"; if ($total == "0"){echo "<tr> <td colspan='2' align='center'>Username was not found!</td></tr>";} while($Ob = $select->fetch(PDO::FETCH_ASSOC)){ echo "<tr> <td align='center'><a href='profile.php?view=".$Ob['username']."'>".$Ob['username']."</a></td><td align='center'>".$Ob['rank']."</td></tr> </tr>"; } } Back on subject, when I echo the rows its found it always says 1 although it never displays the usernames it has found in the loop? Any help will be great! Thanks in advance
  2. Would it be ideal to hold the timestamp in session then? Thank you for the advice about the query in the loop and selecting all so have change them. These JOINS, I've looked up on them on Google as I've not actually used them and they say about Inner Join, Outter Join, Left join, Right join etc, what join would I need to use for my code? Getting my head around them is seeming rather hard right now
  3. Hey guys, I'm currently trying to code an online script which simply displays whos online and a link to their profile. I have coded something similar in MySQL but changing to PDO has made it harder, but anyway, I have a weird problem in which it don't always show when the user is online then when it does after some little time it disappears showing, but when it don't show the user whos online it counts that there is one user online but when it shows the user online it counts two users even though there is only one This is how I update my timestamp in my functions file: $TimeNow = time() + (60 * 10); $LoggedIn1 = $db->prepare("UPDATE UsersRegTable SET timestamp = :timestamp WHERE username = :username"); $LoggedIn1->bindValue(':timestamp', $TimeNow); $LoggedIn1->bindValue(':username', $Username); $LoggedIn1->execute(); This is my online code: <?php $timenow = time(); $UsersTable = $db->prepare("SELECT * FROM UsersRegTable WHERE timestamp > $timenow ORDER by id DESC"); $UsersTable->execute(); $UsersTable1 = $UsersTable->fetchObject(); $NoUsers = "SELECT COUNT(*) as totalusers FROM `UsersRegTable` WHERE timestamp > $timenow"; $NumQuery = $db->prepare($NoUsers); $NumQuery->execute(); $UsersObj = $NumQuery->fetchObject(); $UsersObj->totalusers; $HowManyOnline = ($UsersObj->totalusers) ? "{$UsersObj->totalusers} " : "0"; // Shows correct amount when it shows nobody online but shows wrong amount when displays someones online // $num = mysql_num_rows($select); while ($UsersTable11 = $UsersTable->fetchObject()){ $UsersInfo = $db->prepare("SELECT * FROM UserInfoTable WHERE username = :username"); $UsersInfo->bindParam(":username", $Username); $UsersInfo->execute(); $UsersInfo1 = $UsersInfo->fetchObject(); if($UsersInfo1->userlevel == "2"){ // Admin $Name = "<font color='#000000'>$UsersInfo1->username</font>"; }elseif ($UsersInfo1->userlevel == "3"){ // Owner $Name = "<font color='A7A7A7'>$UsersInfo1->username</font>"; }else{ $Name = "$UsersTable11->username"; } echo "<a href='profile.php?view=$UsersInfo1->username'> $Name </a>,"; } ?> Any help to get me around this would be great appreciated! Thanks
  4. Thanks for your help! I have tried and tested this bit of code but it is still saying that I have no messages yet I know I do. This bit: $inboxCountHtml = ($inbox->unreadCount) ? "{$userInbox->unreadCount} New" : "0"; Has slightly confused me though? Should {$userInbox->unreadCount} be {$inbox->unreadCount} as where did the $userInbox variable come from Thanks for your help
  5. Hey guys, I've not done any coding in a long time although I'm starting to get back into it, using PDO rather than MySQL aswell. On the code below I'm simply trying to pull information from the database to tell the user if he/she has a message, but the problem I've got is its saying I haven't got a message even when I have? Am I missing something completely simple here or have I got to approach this a complete different way than I have done? <?php$Unread = 0;$UsersInbox = $db->prepare("SELECT * FROM `inbox` WHERE `to` = ':username' AND `read` = ':unread'");$UsersInbox->bindParam(":username", $Username);$UsersInbox->bindParam(":unread", $Unread);$UsersInbox->execute();$UsersInbox1 = $UsersInbox->fetchObject();$NumberOfMessage = $UsersInbox->rowCount(); ?><div class="FooterText"><a href="Inbox.php">Inbox</a>(<?php if ($NumberOfMessage != "0"){ echo "New"; }else{ echo "0"; } ?>) Thanks for any help! Dean
  6. I currently have: Scrap that I have it working now thank you! Just had to put the : in the array if (isset($_GET['del'])){ $DoQuery1 = ("SELECT * FROM BoxingResults"); $query1 = $conn->query($DoQuery1); $Obj = $query1->fetch(PDO::FETCH_OBJ); $PostIdThing = $_GET['del']; $idnum = $Obj->id; $delete = "DELETE FROM BoxingResults WHERE id = :boxingid LIMIT 1"; $Startoff = $conn->prepare($delete); if (!$Startoff->execute(array('boxingid'=>$PostIdThing))){ print_r ($Startoff->errorInfo()); }else{ echo ("Result ".$PostIdThing." deleted!"); } }
  7. Hey thanks for your reply, I've tried removing that line but it still does the exact same thing
  8. Hey guys, I've recently started coding again after a long break away from it but I'm trying to learn PDO, so as a Boxing fan I thought I'll try to code my own Boxing Score card. I've not tested it all as of yet but I'm getting a problem when I go to delete a record from the database. Here is the delete part of my code: </tr> <?php $DoQuery = ("SELECT * FROM BoxingResults"); $query = $conn->query($DoQuery); while ($r = $query->fetch(PDO::FETCH_OBJ)){ echo ' <tr> <td align="center" width="">'.$r->FavBoxer.'</td><td align="center" width="">'.$r->R1.'</td><td align="center" width="">'.$r->R2.'</td><td align="center" width="">'.$r->R3.'</td><td align="center" width="">'.$r->R4.'</td><td align="center" width="">'.$r->R5.'</td><td align="center" width="">'.$r->R6.'</td><td align="center" width="">'.$r->R7.'</td><td align="center" width="">'.$r->R8.'</td><td align="center" width="">'.$r->R9.'</td><td align="center" width="">'.$r->R10.'</td><td align="center" width="">'.$r->R11.'</td><td align="center" width="">'.$r->R12.'</td><td align="center" width="" class="header">'.$r->FavPoints.'</td><td align="center" width="" rowspan="2" class="Delete"><a href="index.php?del='.$r->id.'">Delete (X)</a></td> </tr> <tr> <td align="center" width="">'.$r->UnFavBoxer.'</td><td align="center" width="">'.$r->UR1.'</td><td align="center" width="">'.$r->UR2.'</td><td align="center" width="">'.$r->UR3.'</td><td align="center" width="">'.$r->UR4.'</td><td align="center" width="">'.$r->UR5.'</td><td align="center" width="">'.$r->UR6.'</td><td align="center" width="">'.$r->UR7.'</td><td align="center" width="">'.$r->UR8.'</td><td align="center" width="">'.$r->UR9.'</td><td align="center" width="">'.$r->UR10.'</td><td align="center" width="">'.$r->UR11.'</td><td align="center" width="">'.$r->UR12.'</td><td align="center" width="" class="header">'.$r->UnFavPoints.'</td> </tr> <tr> <td colspan="15" class="Uuheader" align="center">Winner: '.$r->Winner.'</td> </tr> <tr> <td colspan="15" class="Uuheader"> </td> </tr>'; } if (isset($_GET['del'])){ $DoQuery1 = ("SELECT * FROM BoxingResults"); $query1 = $conn->query($DoQuery1); $Obj = $query1->fetch(PDO::FETCH_OBJ); $PostIdThing = $_GET['del']; $idnum = $Obj->id; $delete = "DELETE FROM BoxingResults WHERE id = ':boxingid' LIMIT 1"; $Startoff = $conn->prepare($delete); $Startoff->bindValue(':boxingid', $PostIdThing); $Startoff->execute(array(':boxingid' => 1)); if (!$Startoff->execute()){ print_r ($Startoff->errorInfo()); } echo ("Result ".$PostIdThing." deleted!"); } ?> When I click the delete button I'm wanting it to delete the record from the database although currently when I press the delete button its saying its deleted with the correct ID but not actually deleting. I've search over google and just cannot find something to help me. Thanks for any help given.
  9. Hey guys, I've heard about MySQL being replaced with PDO some time in the future, but as a simple question, I'm coding a personal website for my use only, would I still be able to use MySQL rather than changing it to PDO and learning that? Its not going to be anything big or nothing just to keep me active in my spare time. Thanks for you help.
  10. I've got it as if ($_POST['Username']){ At the start then I've got $Username = safe($_POST['Username']); Safe is just my function for abit of security, if I remove that nothing different happens. So my guessing thats wrong? Should I do it like: $Username = safe($_POST['Username'] . ""; Is that how you mean?
  11. I done that and nothing showed I have realised when I made an account which was successful it told did tell me the username
  12. For example like me doing this? $Email = filter_var($_POST['Email'], FLITER_SANITIZE_EMAIL); $CEmail = filter_var($_POST['CEmail'], FILTER_SANITIZE_EMAIL); But no I haven't got anything like that for the $Username. Same thing when I do my Emails like that they never seem to match :S Little typo
  13. When I echo out message its at the end of all the PHP. How would I simply change this in my code?.
  14. Hey guys, I've recently been getting back into coding after a long break of it, I'm currently finishing coding my Registration Script for my Website, although I've came across a few annoying things I cannot work out a way to sort. Below I have a few things I want to throw out an error if done incorrectly. If the Username field is empty I want it to Display the $Message variable, same as with the Password, CPassword and so on. Some reason in which I don't know why its not actually giving me these errors, its not letting the user Register as it shouldn't but its also not telling them why. I have try it a few other ways with the empty($Password) or !$Password etc but nothing changed. if ($Username == ""){ $Message = "Username field was missed."; $Succ = "no"; }else{ $Succ = "yes"; } if ($Password == ""){ $Message = "Password field was missed."; $Succ = "no"; }else{ $Succ = "yes"; } if ($CPassword == ""){ $Message = "Confirm Password field was missed."; $Succ = "no"; }else{ $Succ = "yes"; } if ($Email == ""){ $Message = "Email Field was missed."; $Succ = "no"; }else{ $Succ = "yes"; } On a different note, I do have if ($Password != $CPassword){ $Message = "Your Passwords don't match."; $Succ = "no"; }elseif .... Which works perfectly fine and shows the error. After I've done all that I check that the $Succ variable is not equal to no like this: if ($Succ != "no") { I am displaying the $Message variable like this: echo $Message; Which nothing is wrong with that? Anyone have an idea what I can do to make it show these errors? Thanks for any help in advance
  15. Hey guys, I have got a little function which encrypts users passwords in the database when registering. It all works fine as it inserts into the database and everything, although when I come to log the user in it never generates the same password to have them both to match to login Here is the function: function cryptPass($input, $rounds = 9){ $salt = ""; $saltchars = array_merge(range('A','Z'), range('a','z'), range('0','9')); for ($i = 0; $i < 22; $i++){ $salt .= $saltchars[array_rand($saltchars)]; } return crypt($input, sprintf('$2y$%02d$', $rounds) . $salt); } Here is the part of my login script which checks the password they have entered with the one in the database: $Password = crypt($_POST['Password']); // Have tried $Password = cryptPass($_POST['Password']); didn't work either // Check Password is right with Username: if (strlen($Password) > 0){ $CheckPassDB = "SELECT `username`,`password`,`status` FROM $TblUsers WHERE `username` = '$Username' AND `password` = '$Password' AND `status` = 'Active'"; $DoQuery = mysql_query($CheckPassDB) or die (mysql_error()); // Start Query off $DBObj = mysql_fetch_object($DoQuery); // Get an Object of Query $DBNum = mysql_num_rows($DoQuery); // Count how many rows have been returned if ($DBNum <= 0){ $Message = "Incorrect Username or Password."; $Succ = "no"; }elseif ($DBNum > 1){ How can I add / change something to make my login page work? I'm not sure how to go from here now... If you need any more information I will try to supply you with it. Any help would be greatly appreciated! Thanks in advance.
  16. dean7

    Simple Frames

    Hey guys, I don't really have any knowledge of Frames, so I'm unsure how to actually create a layout I'm wanting. I've tried using google to help me but I can't get my head around how to make a certain design... struggling with this yet I know some PHP... Anyway I'm trying to create a layout which looks like this: --------------------------------------------- | Frame 1 | Frame 5| | | | --------------------------------------------- | Frame 7 | -------------------------------------------- | | | | | | | | | | Frame 2| | Frame 4| | | | | | | Frame 3 | | | | | | | | | | --------------------------------------------- | Frame 6 | --------------------------------------------- Can anyone please show me how to make that. Many thanks!
  17. Hey guys, I've only recently came back into coding as I lost interest although I've got a news script which users can "Like" the news post. Its only a basic script to refresh my memory. Liking the news post all works although how can I check a way that if that user has already liked that news post that user cannot do it agian? I've got this for liking the post: $Like = keepsafe($_GET['like']);if ($Like){ $UpdateLike = mysql_query("INSERT INTO $NewsLikes (`id`,`newsid`,`likedby`,`time`) VALUES ('','".$Like."','".$Username."','".$date."')") or die (mysql_error());echo "Successfully liked that update!"; $GetThingys = mysql_query("SELECT * FROM $TblNews WHERE `id` = '".$Like."' LIMIT 1") or die (mysql_error());$Thingysgot = mysql_fetch_object($GetThingys); $TheNumber = $Thingysgot->likes;$Addon = "1";$NowNumber = $TheNumber + $Addon;$UpdateNewsLike = mysql_query("UPDATE $TblNews SET `likes` = '".$NowNumber."' WHERE `id` = '".$Like."'") or die (mysql_error()); } MySQL Table: id | newsid | likedby | time Quite obviously newsid is the ID from the news which they clicked "like" on. Likedby is the username who liked it Thanks for anyone that helps
  18. Ok, right I'll give it ago with sessions
  19. There the only errors its getting, but with $Code I'm doing: if (strip_tags($_POST['Code'])){ $Code = safe($_POST['Code']); // Then that code. }
  20. Notice: Undefined variable: Output in C:\wamp\www\register.php on line 155 Notice: Undefined variable: Output1 in C:\wamp\www\register.php on line 155
  21. Hey, I'm trying to code a code a user has to input before continuing the registering to my site, for example what I'm trying to do is this: 1 + 3 = 5. So it will randomly give 2 numbers which then the user has to submit the right answer to carry on although its saying I have a undefined variable, which the variable I'm using is defined. My code: if ($Code){$NumberOne = 1;$NumberTwo = 50;$RandomNum = rand($NumberOne, $NumberTwo);$RandomNum1 = rand($NumberTwo, $NumberOne);$Output = $RandomNum;$Output1 = $RandomNum1; // Doing the sum..if ($Output >= 1 || $Output1 >= 1){$Sumfin = $Output + $Output1;$Eq = $SumFin; if ($Sumfin != $Eq){$Message = "Incorrect number adding";$Succ = "no";}elseif ($Sumfin == $Eq){$Succ = "yes";} }elseif ($Output > 50 || $Output1 > 50){$Message = "Something went wrong.";$Succ = "no";}} How I'm out putting it: <td width="50%">Secruity Code:</td><td width="50%"><?php echo $Output;?> + <?php echo $Output1; ?>: <input type="text" name="Code" id="Scode" class="TextInput" maxlength="3"></td> So what can I do here differently to remove the error? Thanks for your help
  22. Yeah I forgot to update this topic, but I changed that but apparently now I'm getting: Cannot redeclare safe() which is : function safe($String){ return "'" .mysql_real_escape_string($String) . "'"; }
  23. Hey , I've just started doing PHP again after a long time of sitting it out. I wasn't the best back then so I'm hoping to improve myself now. I've got a simple script in which it apparently has errors which I'm unsure of and Google didn't exactly help me with. First of all, some odd reason when I try to include an file in my config file its saying no such file or directory even when there is. <?php// connect to DB include ("../includes/functions.php"); $Username = "*****";$Password = "******";$Database = "******";$Server = "localhost"; that is in the folder called includes. And my main problem is about functions. I keep getting a fatal error saying "Unable to call undefined function" in my config file which is: $YourIp = yourip(); In my functions that is: function yourip(){$client = @$_SERVER['HTTP_CLIENT_IP'];$foward = @$_SERVER['HTTP_X_FORWARDED_FOR'];$remote = $_SERVER['REMOTE_ADDR']; if (filter_var($client, FILTER_VALIDATE_IP)){$ip = $client;}elseif (filter_var($foward, FILTER_VALIDATE_IP)){$ip = $foward;}else{$ip = $remote;}return $ip;} (Yes I had help from online with the IP function, but I've got other functions which are exactly the same error) For what I thought that was all fine, but some reason it isnt. Any help getting me pass these error will be grateful. Thanks
  24. Hey all, I stopped coding for some time but I've only just decided to restart coding but already hit into something I can't get around. I've got my Login script for which you will login to on my game. Once logged in you can play untill you logout although, I can login fine but as soon as I get to the first page on my site it sends me back to the login page as it thinks I'm not logged in. Here is my Login Script: Index.php <?php session_start(); include_once ("TheDbs/ConfigerationFile.php"); if (isset($_GET['logout']) && strip_tags($_GET['logout']) == "yes") { session_destroy(); }elseif (isset($_SESSION['username'])){ header("Location: GameIndex.php"); exit(); } if (strip_tags($_POST['Submit']) && strip_tags($_POST['username']) && strip_tags($_POST['password'])){ $username = strip_tags(mysql_real_escape_string($_POST['username'])); $password = strip_tags(mysql_real_escape_string($_POST['password'])); $select = mysql_query("SELECT * FROM $TableUsersInfo WHERE online > '$timenow' ORDER by rank desc") or trigger_error("Query Error, Line 16 . " . mysql_error()); $num = mysql_num_rows($select); $date = date('D, jS M, Y, g:ia'); $ip = getenv("REMOTE_ADDR") ; if((!$username) || (!$password)){ $message="<br /><table width='30%' align='center' class='TableStyle' border='1' cellpadding='0' cellspacing='0'> <tr> <td class='error_header' align='center'>Error</td> </tr> <tr> <td align='center'><strong>Please fill in all fields.</strong></td> </tr> </table>"; } ///check INFO $sql = mysql_query("SELECT * FROM $TableUsers WHERE username='".mysql_real_escape_string($username)."' AND password='".mysql_real_escape_string($password)."' LIMIT 1") or trigger_error("Query Fail, Line 26. " . mysql_error()); $login_check = mysql_num_rows($sql); $infomation = mysql_real_escape_string(mysql_fetch_object($sql)); if ($login_check == "0"){ $message="<br /><table width='30%' class='TableStyle' align='center' cellpadding='0' cellspacing='0' border='1'> <tr> <td class='error_header' align='center'>Error</td> </tr> <tr> <td align='center'><strong>Your Username or Password is incorrect!</strong></td> </tr> <table>"; }elseif ($login_check != "0"){ if ($login_check > "0"){ if ($infomation->status == "Banned"){ $encoded=md5(strtolower($username)); header("Location: BannedUser.php?$encoded=user$banned"); exit(); } session_register('username'); $_SESSION['username'] = $information->username; $timestamp = time()+20; $get = mysql_query("SELECT * FROM $TblUsers WHERE username='".mysql_real_escape_string($username)."' LIMIT 1"); $got = mysql_fetch_object($get); mysql_query("UPDATE $TableUsersInfo SET online='".mysql_real_escape_string($timestamp)."' WHERE username='".mysql_real_escape_string($username)."' LIMIT 1"); mysql_query("UPDATE $TableUsers SET login_ip='".mysql_real_escape_string($ip)."' WHERE username='".mysql_real_escape_string($username)."' LIMIT 1"); mysql_query("UPDATE $TableUsers SET lastlogin='".mysql_real_escape_string($date)."' WHERE username='".mysql_real_escape_string($username)."' LIMIT 1"); header("Location: GameIndex.php"); } else { $message= "<br /><table width='30%' class='TableStyle' align='center' cellpadding='0' cellspacing='0' border='1'> <tr> <td class='error_header' align='center'>Error</td> </tr> <tr> <td align='center'><strong>Error While Trying to Login!</strong></td> </tr> <table>"; }}} ?> <html> <head> <title>Login</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> .ThisBody { background-color: #737373; margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; font-family: Verdana; font-size: 11px; font-style: normal; color: #FFFFFF; } </style> <link rel='stylesheet' href='includes/style.css' type='text/css'> </head> <form action='' method='post'> <br /> <body class='ThisBody' leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> <?php echo ($message); ?> <table id="Table_01" align='center' width="530" height="292" border="0" cellpadding="0" cellspacing="0"> <tr> <td colspan="7" background="images/LoginScreen/Indexright.png" height='220' align='center'><br /><br /> <img src='images/LoginScreen/Username.png'><br /><input name="username" class='TextInput' type="text" maxlength="15" id="username"><br /> <img src='images/LoginScreen/Password.png'><br /><input name="password" class='TextInput' type="password" maxlength="30" id="password"><br /><br /> <input type="submit" class='Button' name="Submit" value="Login SC"> </td> </tr> </table> </form> <br /> <table align="center" cellpaddig='0' cellspacing='0' border='1' width="35%" class='TableStyle'> <tr> <td class='UnderTable' align='center'>Help:</td> <tr> <td colspan="2" width="100%" align="center"><a href="Register.php">Register</a> - <a href="TOS.php">Terms Of Service</a> - <a href="LostPassword.php">Lost Password</a></td> </tr> </table> And simply on my gameindex page its a simple piece of code for the moment: GameIndex.php <?php session_start(); include ("TheDbs/ConfigerationFile.php"); include ("TheDbs/GameFunctions.php"); logincheck(); $Username = $_SESSION['username']; ?> Game Index And the last thing is the function logincheck() is another reasonably simple code: function logincheck(){ if (empty($_SESSION['username'])){ echo " <SCRIPT LANGUAGE='Javascript'> window.location='Index.php'; </script> "; exit(); }} Thanks for any help! =D
  25. Hey all, I've coded an online script for my website which works perfectly although when it shows whos online I'm wanting it to order the usernames in alphabetical order, I have this so far: $select = mysql_query("SELECT * FROM $TblUsersInfo WHERE online > '$timenow' ORDER BY 'username' ASC") or trigger_error ("Error on line " . __LINE__ . mysql_error()); while ($i = mysql_fetch_object($select)){ echo "<a onmouseover=\"ddrivetip('<u><b>$i->username Stats</b></u>:<br /><code>> Username</code>: $i->username <code><</code><br /><code>> Rank</code>: $i->rank <code><</code><br /><code>> Location</code>: $i->location <code><</code><br /><code>> Crew</code>: $crew <code><</code><br /><code>> Userlevel</code>: $userlevel <code><</code>');\" onMouseout=\"hideddrivetip()\" href='profile.php?username=$i->username'>$echo</a> : "; } But what I've got there it is ordering by the ID even though I've got ORDER BY 'username' in the Query, how would I change it so its in alphabetical order? Thanks for any help
×
×
  • 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.