Jump to content

Display Message to User if Value is "x"


Call-911

Recommended Posts

Hello All,

 

I have a login system on my website using a mySQL database. What I need to do is display a message to users upon logging to please update their contact information. I don't want to display this to every user, as that would be annoying, but only to the users that have no updated their information.

 

For example, if John Doe's email address is "No Email On File"  then I would like upon John Doe logging in a message to pop up saying "Please update your contact information"

 

Any help is great appreciated.

Link to comment
Share on other sites

This is simple to do- but difficult to explain.. and your implementation of the code depends entirely on your comfort level with php.

 

Obviously the error message can only be displayed after logging in to determine if the user has or does not have an e-mail. So, you'll have to grab the users e-mail address when they log in and pass it as a $variable to the first page they see after logging in. Then you'll need to write an if/else statement on that page to determine one way or the other if they have an e-mail address.

 

the concept is: If this users e-mail has an "@" symbol- or "@domain.com" then display nothing. Else, display the following alert message. Which you will have to code and customize using echo strings, html, and css.

 

I have to run for an hour. I'll leave you with that for now-- and if the topic still isn't solved when I get back I'll write you some code to work from.

Link to comment
Share on other sites

Alllllright. Looks like have some code to give you.

 

first, put on "Little Acorns" by the White Strips- even if you don't like them, it will help.

 

Next, look at my code. This is how I process my login. The login form passes the variables to this code in a php document I've called login-exec.php

 

<?php

//Start session

session_start();

 

//Connect to mysql server

$link=mysql_connect("host","user","password");

if(!$link) {

die('Failed to connect to server: ' . mysql_error());

}

//Select database

$db=mysql_select_db("databasename");

if(!$db) {

die("Unable to select database");

}

 

//Sanitize the value received from login field

//to prevent SQL Injection

if(!get_magic_quotes_gpc()) {

$login=mysql_real_escape_string($_POST['login']);

}else {

$login=$_POST['login'];

}

 

//Create query

$qry="SELECT id, email FROM tbmembers WHERE login='$login' AND passwd LIKE'".md5($_POST['password'])."'";

$result=mysql_query($qry);

//Check whether the query was successful or not<a href="login-exec.php">login-exec.php</a>

if($result) {

if(mysql_num_rows($result)>0) {

//Login Successful

session_regenerate_id();

$member=mysql_fetch_assoc($result);

$_SESSION['SESS_EMAIL']=$member['email'];

                        $_SESSION['SESS_MEMBER_ID']=$member['id'];

session_write_close();

//Redirect Based on Permission Number<br />

header("location: main-page.php");

exit();

}else {

//Login failed

header("location: login-failed.php");

exit();

}

}else {

die("Query failed");

}

?>

 

 

 

There is a lot going on in that code. Essentially I've processed the log-in and set a Session variable. This means as long as the person is logged in you will be able to interact with that variable on the subsequent pages. I'm not gonna go into too much detail here. You'll have to do some googling to figure out any terms you don't understand.

 

Now that we have set a session variable we need to include it and authorization on any page you wish to make reference to it. Make a file called auth.php and in it put the following code (modified to suit your needs).

 

<?php

//Start session

session_start();

//Check whether the session variable

$id=$_SESSION['SESS_MEMBER_ID'];

$email=$_SESSION['SESS_EMAIL'];

 

//SESS_MEMBER_ID is present or not

if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID'])=='')) {

header("location: access-denied.php");

exit();

}

?>

 

Then you need to use require_once on any pages you wish to be secure and make reference to the e-mail. Put the following code at the top of the page you want the error message to appear on. If you are not logged in this requre_once code will redirect you to access-denied.php or show you a blank page... so until you have the login working properly.. this may cause issues.

 

<?php

require_once('auth.php');

?>

 

 

Finally the code to generate the error message will look something like this:

 

<?php

if($email == "No Email On File") {

echo "Give us your e-mail, fool";

}else{

echo "";

}

?>

 

The string "No Email On File" is kinda clunky and might cause issues here. I'm not prepared to test it for you. the bolded area is where you will echo your error message.

 

You should know, this code won't work unless you modify it to suit your needs. Stare at it long enough.. and you're bound to figure it out.

 

That's the best I can do. Hope it Helps.

 

Link to comment
Share on other sites

pwnuspoints,

 

Thanks so much. I've got the whole login system already set up and coded perfectly. What I can't figure out is how to display a popup message. Almost like an error message. A message like on MS Word when you exit it pops up a box saying "Are You Sure You Want To Quit Without Saving". That's the kind of box I need.

 

I already have the email variable being read on the page, so if $email == "No Email On File"  to pop up a message box and say "Please Update Your Contact Information" ....  or I guess "Update your email fool!" works too. :-)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.