PHP - Cant Log-in With Unique Id
Hello PHP freaks,
my codes dont allow me to log-in to Student Home with unique id. It says "Invalid Login or Password"
this is my form
<tr bgcolor="#E1E1E1" class="stylesmall"> <td width="35%" align="left" class="style7 style1">Learner Id : </td> <td width="65%" align="left"><input name="learner_id" type="text" id="learner_id" action="Student_Home.php" method="post"></td> </tr> <tr bgcolor="#E1E1E1" class="stylesmall"> <td align="left" class="style7 style1">Password:</td> <td align="left"><input name="student_password" type="password" id="student_password">< /td>and this is my handler. <?php session_start(); include 'Connect.php'; $flag = ""; $learner_id = $_POST['learner_id']; $student_id = $_POST['student_id']; $student_password = $_POST['student_password']; $query = "select last_login_date from student_information where student_id='$student_id' and student_password='$student_password'"; $result = mysql_query($query,$link_id); if(mysql_error() != null){ die(mysql_error()); } if($date = mysql_fetch_array($result)) { $lastdate = $date['last_login_date']; $date2 = date("d-m-Y h:i A",strtotime($lastdate)); $_SESSION["student_id"] = $_POST["student_id"]; $_SESSION["lastlogin"] =$date2; $_SESSION["type"] = "Student"; mysql_query("UPDATE student_information SET last_login_date=now() where student_id='$student_id'",$link_id); if(mysql_error() != null){ die(mysql_error()); } header("location: Student_Home.php?id={$student_id}"); die(); } else { $flag = "invalid"; header("location:Student_login.php?flag=$flag"); die(); } ?>PLease help me PHP friends to correct my codes. Similar TutorialsI have a mysql table which will store users email addresses (each is unique and is the primary field) and a timestamp. I have added another column called `'unique_code' (varchar(64), utf8_unicode_ci)`. What I would very much appreciate assistance with is; a) Generating a 5 digit alphanumeric code, ie: 5ABH6 b) Check all rows the 'unique_code' column to ensure it is unique, otherwise re-generate and check again c) Insert the uniquely generated 5 digit alphanumeric code into `'unique_code'` column, corresponding to the email address just entered. d) display the code on screen. What code must I put and where? **My current php is as follows:** Code: [Select] require "includes/connect.php"; $msg = ''; if($_POST['email']){ // Requested with AJAX: $ajax = ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'); try{ if(!filter_input(INPUT_POST,'email',FILTER_VALIDATE_EMAIL)){ throw new Exception('Invalid Email!'); } $mysqli->query("INSERT INTO coming_soon_emails SET email='".$mysqli->real_escape_string($_POST['email'])."'"); if($mysqli->affected_rows != 1){ throw new Exception('You are already on the notification list.'); } if($ajax){ die('{"status":1}'); } $msg = "Thank you!"; } catch (Exception $e){ if($ajax){ die(json_encode(array('error'=>$e->getMessage()))); } $msg = $e->getMessage(); } } Howdy, The following code wil geenrate a dynamic pull-down list based on column values. Can someone help me tweak it so that is will NOT display a duplicate record value. That is, if the sponsors values in the table were Hart, Michaels, Michaels, Morella ...it would only display Hart, Michaels, Morella in the pull-down menu. <form name="form0"> <? $result = @mysql_query("select distinct sponsor from table ORDER BY sponsor ASC"); if (mysql_num_rows($result) > 0) { print "<select name=\"link\">"; ?> <option <?php if(empty($_GET['sponsor'])){ echo "selected=\"selected\""; } ?> value="<? echo "$page_name" ?>">SELECT A SPONSOR</option> <? while ($row = mysql_fetch_array($result)) { print "<option "; if($_GET['sponsor'] == $row['sponsor'] ){ echo "selected=\"selected\""; } print " value=\"index?sponsor=" . $row['sponsor'] . "\">" . $row['sponsor'] . "</option>\n"; } print "</select>"; } ?> </form> Thank you. ~Wayne Hey everyone! My upcoming site will host, potentiallly thousands of photographs, and i was wondering how to go about having a unique ip hit counter for EACH image. Obviously i dont want people refreshing the page to gain hits, therefore the hit counter will need to be dependent on the IP address. I have used google and found a few hit counters however i need to know how to make this practical as it seems like it will require a lot of databases! Thanks in advanced, Jimmy. Hi: Not sure if this is where to ask this (maybe it's a mySQL Issue)?? I am working on a zip code locator. The field/column "zip" (which holds the zip codes) is set as a UNIQUE Key in the database. Problem is: I want to allow people to enter a new city if there is one they want to add. The only way I can do this is to remove the UNIQUE Key from the column, or I get an error. Some cities - like Malvern, PA and Frazer, PA - have the same zip code: 19355 This works fine, but the issue that now happens is the zip locator on the frontend will no longer find that zip code. Does anyone know what a solution might be? I can post the zip locator code, and maybe there's a chunk of code I can remove or alter to fix this? Not sure how to address this one. what is the easiest way to get unqiue sub arrays based on date from within my larger array? here is what i mean in detail. I have an array that outputs this... Code: [Select] [0] => Array ( [date] => 2010-11-02 [time] => 7:00 p.m. [location] => Illinois [team1] => [team1sc] => [team2] => [team2sc] => [winner] => Illinois ) [1] => Array ( [date] => 2010-11-02 [time] => 7:15 p.m. [location] => Purdue [team1] => University of Indianapolis [team1sc] => 59 [team2] => Purdue [team2sc] => 82 [winner] => Purdue ) [2] => Array ( [date] => 2010-11-06 [time] => 3:05 p.m. [location] => Southern Illinois [team1] => University of Indianapolis [team1sc] => 58 [team2] => Southern Illinois [team2sc] => 65 [winner] => Southern Illinois ) I don't need value [ 1 ] because value [ 0 ] already has the same date! My goal is to get a list of all the unique [date]s from this entire multidemonsional array. (FYI - I know I will be loosing blocks of arrays that have duplicate dates - THATS OK). But it's a bit of a struggle for me unique array sections out of this...any help or advice would be great! thanks! Hi i'm making a new website based on PHP. I bumped on a problem now... The problem is that I have a loop where i get all records out of my sql database and get them into a form. Every record has a differend form with a button to. Every button then has a unique ID. Now i tried everyting i could think of to get the value out of a button when a button is clicked. But nothing worked... here is the part of the code where everything is for the form and the POST. Code: [Select] while($record = mysql_fetch_object($result)){ $id = $record->id; echo"<form action='home.php' method='post'>"; echo"<b>name:</b>".$record->name." <b>Price: </b>".$record->price.""; echo'<input type="hidden" name="id" value='.$id.'>'; echo"<input type='submit' value='Buy' /><br />"; echo"</form>"; } if($_POST) { $ID = intval($_POST['id']); $query1 = "SELECT price FROM items WHERE id = ".$ID.""; $result1 = mysql_query($query1); list($cost) = mysql_fetch_row($result1); $gold = getStat('gc',$userID); if($gold > $cost) { setStat('gc',$userID,($gold - $cost)); $queryw = "INSERT INTO users_inventory(item_id,user_id, quantity) VALUES ('".$ID."','".$userID."','1')"; $resultw = mysql_query($queryw); } else { echo"You can't afford this weapons."; } } The only thing that doesn't seem to work is this part Code: [Select] $ID = intval($_POST['id']); is always gives me this error: Notice: Undefined index: id in shop.php on line 26 Please help me out here i have no idea what to do from here on... I have a foreach parsing as foreach ($posttags as $tag) { $test = $tag->name; $pattern = "/something/"; if(preg_match($pattern, $test)) { $test2 = "$test is $test"; echo $test2; } } I selected those containing a given word, but I do not know how to remove duplicates to have uniqueness. I was unable to use array_unique, as I am within a foreach loop. Need a bit of help with some php and a few kind members helped me in the past. My code is: $query = "SELECT names FROM table WHERE type='$type'"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { foreach(unserialize($row['names']) as $key => $value){ echo $value . '<br />'; } } Basically, a field on my table is called names. The information in this field is serialized (so many names are together in a single field, for a single row). I want to be able to search the whole table (where type='$type' - so many rows) for all names and then show unique names only. My code above unserializes the names from each field and then lists them, but doesn't deal with any duplicates (which I need removing). I have looked at functions like "unique_array()", and have tried using it in different places but it isn't doing the job. Any help appreciated. hi, im trying to create a website and only now started thinking about the security part(noob mistake). say for example i have home.php page and an index.php page. index.php is where users would sign up/log in. the login and sign up processes are all done but i was thinking of creating a unique id of some sort for when the user logs in. or something like this site (forum.phpfreaks) when we sign in, you are signed but the url stays the same = forums.phpfreaks.com. like if we were signed out we will be permanantly signed out and typing in forums.phpfreaks.com would just land us at the main page where we need to sign in.
right now ,my home.php can be accessed with or without logging in even with sessions.
hope im making sense, thanks in advanced!
**haha that rhymed.
i tried adding:
<?php echo $_SERVER[PHP_SELF] . '?name=' . $userData['name'];?> in the index.php:
<?php ob_start(); session_start(); if(isset($_POST['login'])) { $email = $_POST['email']; $password = $_POST['pass']; require "connection.php"; $emails = mysqli_real_escape_string($con, $email); $query = "SELECT id, name, email, password, salt FROM users WHERE email = '$emails';"; $result = mysqli_query($con, $query); if(mysqli_num_rows($result) == 0) // User not found. So, redirect to login_form again. { echo "<script>alert(\"User does not exist!\")</script>"; } $userData = mysqli_fetch_array($result, MYSQLI_ASSOC); $hash = hash('sha256', $userData['salt'] . hash('sha256', $password) ); if($hash != $userData['password']) { echo "<script>alert(\"Incorrect Password!\")</script>"; }else{ session_regenerate_id(); $_SESSION['sess_user_id'] = $userData['id']; $_SESSION['sess_name'] = $userData['name']; session_write_close(); header('Location: home.php?user='); } } ob_flush(); ?> <!DOCTYPE html> <form name="login" method="post" action="<?php echo $_SERVER[PHP_SELF] . '?name=' . $userData['name'];?>">but i got access forbidden! Edited by noobdood, 19 May 2014 - 10:05 PM. ok so i have an array which has duplicate values in it. i used array_unique() to remove duplicate values. the array had values 1,2,2,3. after the following code: $unique = array_unique($suggest); $size = count($unique); for ($x=0;$x<=$size;$x++) { echo $unique[$x]; echo "<br>"; } it prints out 1,2 and then gives an error, "Notice: Undefined offset: 2 in E:\wamp\www\Copy of pro2\Classes.php on line 1074" and then finally 3. any ideas how i can solve this. im assuming that array_unique() assigns the index 0,1,3 of the duplicate value array to unique array at the same indexs 0,1,3. since the index 2 of duplicate array is a duplicate value it is ommited but the unique array does not have an array at index 2. Whats the easiest way to rename uploaded files to a unique name that would never be duplicated? Hey guys. I need to know how to get a time that is constant. What I want to achieve: I need to make a clock on my website showing only one time (HH:MM:SS), wherever the page is requested from. And I need to use this "time" in calculations, like finding the time difference between two time values stored in my MYSQL Databases. I hope that I am clear with my question. Thanks for any help in advance! i have table in my db that has rows of dates, for example... id | date | created | display | group | 1 | 2011-05-24 00:00:00 | 2011-05-24 20:00:00 | Y | 20 | 2 | 2011-05-24 00:00:00 | 2011-05-24 22:00:00 | N | 20 | 3 | 2011-05-26 00:00:00 | 2011-05-26 22:00:00 | N | 20 | 4 | 2011-05-27 00:00:00 | 2011-05-26 22:00:00 | N | 20 | 5 | 2011-05-27 00:00:00 | 2011-05-30 22:00:00 | N | 20 | Now i'm trying to make sure that each group has no duplicate dates. If they do delete all but the newest. So in this case, after the code ran, it would have deleted row 2 and row 5 because they both have duplicate dates and they're the oldest of those particular duplicates. I posted in the PHP board and not the MySQL board because it's the logic i can't figure out. I believe array_unique() would come in handy but i can't wrap my head around how to use it to do what i want. Hi, I just need someone to check that a couple of lines I've written do what I believe them to do... i.e. check my logic! I'm developing a booking form for booking on events. Each booking needs a unique reference, which needs to be meaningless to the customer, so I am BASE36 encloding it. As the booking is be saved to a MySql database, my approach is to use the auto-incremented ID for the record to make the reference unique. The increment starts at 10000, and I add a random number before coding to make the encoded reference longer. I then BASE36 encode it to make it appear random. Am I right in thinking the reference produced WILL be unique ... provided the auto-inc ID is unique? $ref = rand(100,999) . $auto_incremented_id; //e.g. 354 & 10012 = 35410001 $ref_encoded = strtoupper(base_convert($rand, 10, 36)); // e.g.UD4J8P Thanks Hey everyone. I have been working on a cart for my site and I've reached an impasse. I coded up the cart, the add to cart, the delete from cart and the subtract from cart. Problem is I now see a need to put an image for everything that is added to the cart. I think i have devised a way to do it with frames, the left frame being the cart and the main frame is purely for the images. I am having trouble getting the code right between the two pages to work. I need a picture on the right of every item added to the cart. Here is the url for the cart: http://www.theblack44s.com/Merchant%20pages/index3.php I know this kind of thing can get extensive and I don't mean to take up any more of your time than necessary so if there are any suggestions or ideas of where I can find this information to learn it that would be just as good. Hey thanks for your time! A $info[130] is the random code, but how do i go about making sure the code is not used on any other row.... (even thou it would be unlikely even with this code, it is still possible) Code: [Select] <?php # IF THE USER DOES NOT HAVE A UNIQUE CODE, CREATE ONE if ($info[130] == "0") { function randomPassword() { $salt = "abchefghjkmnpqrstuvwxyz0123456789"; srand((double)microtime()*1000000); $i = 0; while ($i <= 14) { $num = rand() % 33; $tmp = substr($salt, $num, 1); $pass = $pass . $tmp; $i++; } return $pass; } $info[130] = randomPassword(); } ?> Hey all, I'm trying to upload multiple image(which works great) but the problem I'm having is when an image is uploaded it over-rights a previous image if they are the same name and the old one is gone. Solution: create a unique name for each image before it's uploaded, change the name and then upload it. I can't seem to figure the correct syntax. My thought was to take the image name and add a random number to the front of it. Am i going about this the right way? thanks for the replies in advance. code below Code: [Select] if (isset($_POST['Submit'])) { $number_of_file_fields = 0; $number_of_uploaded_files = 0; $number_of_moved_files = 0; //creating my random number $random_digit=rand(0000,9999); $uploaded_files = array(); $upload_directory = dirname(__file__) . '/car-images/'; //set upload directory for ($i = 0; $i < count($_FILES['images']['name']); $i++) { $number_of_file_fields++; if ($_FILES['images']['name'][$i] != '') { //check if file field empty or not $number_of_uploaded_files++; $uploaded_files[] = $_FILES['images']['name'][$i]; if (move_uploaded_file($_FILES['images']['tmp_name'][$i], $upload_directory . $_FILES['images']['name'][$i])) { $number_of_moved_files++; } } } $image0 = $uploaded_files[0]; $image1 = $uploaded_files[1]; $image2 = $uploaded_files[2]; $image3 = $uploaded_files[3]; $image4 = $uploaded_files[4]; Hi guys, How would I write a small script in php to count the unique values in the below array : the below code if part of cubecart 3.20 shopping cart, I need to count the unique number of Seller_ID fields within this array in the basket to be able to calculate shipping according to the number of sellers. How would I to this ? please any help is appreciated. Code: [Select] if(isset($_GET['act']) && $_GET['act']=="step4"){ // set live vars for order inv and its the last step $view_cart->assign("QUAN_DISABLED","disabled"); $view_cart->assign("TEXT_BOX_CLASS","textboxDisabled"); $basket = $cart->setVar($productId,"productId","invArray",$i); $basket = $cart->setVar($product[0]['name'],"name","invArray",$i); $basket = $cart->setVar($product[0]['productCode'],"productCode","invArray",$i); $basket = $cart->setVar($plainOpts,"prodOptions","invArray",$i); $basket = $cart->setVar(sprintf("%.2f",$price*$quantity),"price","invArray",$i); $basket = $cart->setVar($quantity,"quantity","invArray",$i); $basket = $cart->setVar($product[0]['digital'],"digital","invArray",$i); $basket = $cart->setVar($product[0]['Prod_Seller'],"Prod_Seller","invArray",$i); $basket = $cart->setVar($product[0]['Seller_ID'],"Seller_ID","invArray",$i); } else { $basket = $cart->unsetVar("invArray"); } hii i had created a site but i'm facing one problem. where users had to show there page to earn money... like 1000 imp/1$. but what happened is that when ever page reloads in same browser with same ip, it gaining impression. is there any way that i can limit 1 impression per ip in 24 hours... Any help will be appreciated... |