how to get the admin username ?

Hiii all ,

This is my first post and I wish I would be one of this amazing php family :slight_smile:

I have one year experience in PHP , my company asked me to do the following project :

Registration form for some restaurant which they offer free meal for users who signed up online !

User registers , gets random code which is a voucher code …

From my side , I have created everything database , registration form and I the developing part …

For the admin page , there will be 3 branches from this restaurant where the user will go and shows the managerhis voucher code (number) , the manager will login ( will find search form) , type the voucher number and click on search button … if it exists , the manager in the admin page set the voucher as reedemed . It should also update the database with which admin with the date he has updated the voucher code as reedemed .
My login page is very simple … I used post method where it goes to checklogin.php page then goes to admin1.php ( in case username and password is correct )

here is my check_login.php

[php]<?php require_once(’…/Connections/connection.php’);




$username = $_POST[‘username’];
$password = $_POST[‘password’];
$sql = mysql_query("SELECT * FROM admins where username = ‘$username’ AND password = ‘$password’ ");
$num_rows = mysql_num_rows($sql);
if ( $num_rows == 1 ){
$_SESSION[‘access’] = true;
header(“location: admin1.php”);

else {  
echo header("location: login.php");; } 


If the manager enters the system with correct username and password , it takes him to admin1.php page where I have simple search form which displays the info of the voucher code if it exists


<?php session_start(); // starting the session $_SESSION['term'] = $_POST['term']; $_SESSION['username'] = $_SESSION['username']; ?> <?php

if (!empty($_REQUEST[‘term’])) {

$term = mysql_real_escape_string($_REQUEST[‘term’]);
$sql = “SELECT * FROM mydata WHERE id2 LIKE '%”.$term."%’";
$r_query = mysql_query($sql);
$num_rows = mysql_num_rows($r_query);

if ( $num_rows == 1 ){
while ($row = mysql_fetch_array($r_query)){
echo 'id: ’ .$row[‘id’];
echo ’
Entry Date: ’ .$row[‘entry_date’];
echo ’
Name: '.$row[‘fname’];
echo ’
Email: '.$row[‘email’];
echo ’
Mobile: '.$row[‘mobile’];
echo ’
Voucher Code: '.$row[‘id2’];
if ( $row[‘reedemed’] == 1) {
echo ’
Reedemed: '. ‘Reedemed’;
else {?>

Mark as reedemed <?php } echo '
Updatedby: '.$row['updatedby']; } } else {echo '';} } ?>[/php]

my problem is in the following part ( HOW TO GET WHICH ADMIN HE SETS THE CODE AS REEDEMED ) ?

[php]<?php require_once('../Connections/connection.php'); ?>

<?php session_start(); ?> <?php $term2 = $_POST['term2']; $term = $_SESSION['term']; mysql_query("UPDATE mydata SET reedemed='1' WHERE id2 = '$term' "); echo 'Your voucher code has been marked as reedemed. Thank You!'; //updatedby part $sql = "SELECT * FROM mydata WHERE id2 LIKE '%".$term."%'"; $r_query = mysql_query($sql); $row = mysql_fetch_array($r_query); $mydate= $row['entry_date']; $num_rows = mysql_num_rows($r_query); if ( $num_rows == 1) { mysql_query("UPDATE mydata SET updatedby = '$mydate' WHERE id2= {$term} ; "); } ?>[/php]

Please I need help ASAP :frowning: ?


In addition to setting session access to true you could also set session userId to the user logging in. Then when you update the redeem code you just insert that user id :slight_smile:

Btw. mysql_* functions are deprecated, you should switch to pdo or mysqli

Sponsor our Newsletter | Privacy Policy | Terms of Service