Solved

Add email prefix

Posted on 2012-04-03
15
450 Views
Last Modified: 2012-05-10
I'm hoping to add email prefix @mydot.ie
A student have to register a module and picked moduleNo1. A student then provide a student ID and password and selected module on a simple from.
A student ID is 12345 and it is automatically generating the email address using the ID. The email address is now 12345@mydot.ie.
This php code as below is a lecturer query for students name and email address. I've moduleNo1 and moduleNo2, maybe a drop down menu to show a query result of moduleNo1 and moduleNo2 separately? Please advise?

<?php

$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'root';
$dbname = 'mydotData';

$q=$_GET["q"];
$table = "lecturerTable";
$conn = mysql_connect($dbhost, $dbuser, $dbpass);

if (!$conn)     
	die('Could not connect: ' . mysql_error());
if (!mysql_select_db($dbname))    
	die("Can't select database");	
	
$result = mysql_query("SELECT * FROM {$table} WHERE staffNumber = '".$q."'");
if (!$result)  
	die("Query to show fields from table failed!" . mysql_error());
	
while($row = mysql_fetch_array($result))
{
echo "<p> First Name: " . $row['firstName'] . "</p>";
echo "<p> Last Name: " . $row['lastName'] . "</p>";
echo "<p> Teaching Module: " . $row['moduleNo1'] . "</p>";
echo "<p> Teaching Module: " . $row['moduleNo2'] . "</p>";
echo "<p> Email: " . $row['email'] . "</p>";
}
//mysql_free_result($result);
mysql_close($conn);
?>

Open in new window

0
Comment
Question by:Redscrapbook
  • 8
  • 3
  • 2
  • +1
15 Comments
 
LVL 51

Accepted Solution

by:
ahoffmann earned 84 total points
Comment Utility
what exactly is your problem with the value in $row['email'] ?

BTW, I highly recommend to replace
   $q=$_GET["q"];
by something like:
   $q=preg_replace("/[^a-zA-Z0-9_.-]/","",$_GET["q"]);
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
Comment Utility
When you use a query that says SELECT * FROM... your query is telling the data base to select all columns without regard to the names of the columns.  In other words, this query does not "know" what the columns are!  Inside your while loop you can use var_dump() to print out the contents of the rows from the data base.  Then you can identify the columns you want and use their names (and perhaps aliases) in the SELECT query.  Please do that and post the output here so we can see what is in the data base.  Then we may be able to help you get the information formatted in a way that is useful for your needs.

I agree with ahoffmann about sanitizing the external input before using it in a query string.  You may want to learn about this function before hackers destroy your data base.  NEVER, EVER use unfiltered external input for any purpose whatsoever.
http://us.php.net/manual/en/function.mysql-real-escape-string.php
0
 

Author Comment

by:Redscrapbook
Comment Utility
This is student table with studentID on field.This is student table on browse and you can see the list of studentID and moduleNo1.This is a Dreamweaver CS5.5 phonegap of a design. A student register a moduleNo1 (Digital Audio) or moduleNo2 (Motion Graphics) with a studentID provided and register.This is my MAIN question of this WHOLE solution. When a lectuer click Digital Audio student list and see a list of students email addresses ONLY.Thank you ahoffmann and Ray for your replies. I appreciated it. My php skills is limited so my apologies beforehand.

I've attached a screen grabs of mamp of students and list of studentsID.
And student register a module of their choice and register.  

As attached image no4: This is my MAIN question of this WHOLE solution.
When a lectuer click Digital Audio student list and see a list of students email addresses ONLY for that module and click Motion Graphics student list and see a list of students email addresses ONLY for that module.

There is no email address in a database. Only studentID. When a lecturer click Digital Audio student list and see a list of students email addresses ONLY for that module.
The query the table data with studentID only and php can attach a prefix @mydot.ie of students email addresses.

Then a lecturer will see 123@mydot.ie, 124@mydot.ie, 127@mydot.ie and so on. Limited to ten students.

I hope I make sense?
0
 

Author Comment

by:Redscrapbook
Comment Utility
To explain better to what I'm talking about.

    $peopleid = "12345";
    $suffix = "@dot.com";
    $email = $peopleid . $suffix;
    where $email' then contains "people@dot.com" with MySQL

This is what I've come up with with string operator.

To explain better to what I'm talking about.
    $studentID = "12345";
    $suffix = "@dot.com";
    $email = $studentID . $suffix;
    where $email' then contains "student@dot.com" with MySQL

This is what I've come up with with string operator.

$emails = array();
$query = "SELECT *, CONCAT('studentID', '@dot.com') AS 'Email' FROM 'student'";
$result = mysql_query($query,$conn_to_database);

while($row = mysql_fetch_object($result)):
   $emails[] = $row->Email;
endwhile;

Open in new window

0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
Comment Utility
In PHP you can create the concatenated variable like this
$peopleid = "12345";
$suffix = "@dot.com";
$email = $peopleid . $suffix;

Open in new window

Then you can use the created variable in a query like this:
$sql = "SELECT * FROM people WHERE email = '$email' LIMIT 1";

Open in new window

0
 

Author Comment

by:Redscrapbook
Comment Utility
Did you see my earlier post as soon you post yours as below::

$emails = array();
$query = "SELECT *, CONCAT('peopleID', '@dot.com') AS 'Email' FROM 'people'";
$result = mysql_query($query,$conn_to_database);

while($row = mysql_fetch_object($result)):
    $emails[] = $row->Email;
endwhile;

Open in new window

0
 

Author Comment

by:Redscrapbook
Comment Utility
Thanks Ray fro your reply. What is the different between post as above and below?
$sql = "SELECT * FROM people WHERE email = '$email' LIMIT 1"; 

Open in new window


Will it show email list maybe ten emails? Is
$email' LIMIT 1"; 

Open in new window

instead of limit one and could I adjust limit to ten?
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
Comment Utility
... instead of limit one and could I adjust limit to ten?
Uhh, sure.  But email addresses are unique in all the world.  How would a limit of 10 rows be expected to produce a result that would be different from LIMIT 1?  If you want to step back from the technical details of this question and just describe in plain language what you're trying to achieve we may be able to show you a well-understood design pattern.
0
 

Author Comment

by:Redscrapbook
Comment Utility
All will be same email in a same company example @dot.com with student number as studentID see as below.

---------------------------------------------
12345@mydot.ie
---------------------------------------------
12345@mydot.ie
---------------------------------------------
23454@mydot.ie
---------------------------------------------
45691@mydot.ie
---------------------------------------------
2354@mydot.ie
---------------------------------------------
1234@mydot.ie
---------------------------------------------
00065@mydot.ie
---------------------------------------------
76532@mydot.ie
---------------------------------------------
99009@mydot.ie
---------------------------------------------
00001@mydot.ie
---------------------------------------------
0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 166 total points
Comment Utility
0
 

Author Comment

by:Redscrapbook
Comment Utility
------------------------------------------------------
|  studentID  | firstName| lastName  |  
------------------------------------------------------
| 123             | Kermit      | Frog           |
| 124             | Gonzo      |Great           |
| 125             | Cookie     |mosnter      |
------------------------------------------------------
FIGURE 1

This is what we will see on a database studentTable, you'll see studentID, firstName and lastName. The database does not have students email addresses as above. The email address is @mydot.ie and all students will have a same email address with a studentID.

For example as below (FIG 2) a studentID is 123 and there is no email address. A string operator to create the concatenated variable like this 123@mydot.ie . That is one example.

------------------------------------------------------
|  studentID  | firstName| lastName  |  
------------------------------------------------------
| 123             | Kermit      | Frog           |
------------------------------------------------------
FIGURE 2

What I'm looking for is query return with ten email addresses (FIG 3) as below with database record as FIG1.

---------------------------------------------
12345@mydot.ie
---------------------------------------------
12345@mydot.ie
---------------------------------------------
23454@mydot.ie
---------------------------------------------
45691@mydot.ie
---------------------------------------------
2354@mydot.ie
---------------------------------------------
1234@mydot.ie
---------------------------------------------
00065@mydot.ie
---------------------------------------------
76532@mydot.ie
---------------------------------------------
99009@mydot.ie
---------------------------------------------
00001@mydot.ie
---------------------------------------------
FIGURE 3

NOTE TO REMEMBER: I'm using jQuery 1.6.4 so a script has to work with it. Thanks.
0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 166 total points
Comment Utility
$query = "SELECT *, CONCAT('peopleID', '@dot.com') AS 'Email' FROM 'people' LIMIT 10";
0
 

Author Comment

by:Redscrapbook
Comment Utility
This is what I've come up with so far with database connectivity that works. When I run it on MAMP to test on a localhost and see a white blank page. I could not figure out why?

This is what is on studentTable database.
------------------------------------------------------
|  studentID  | firstName| lastName  |  
------------------------------------------------------
| 123             | Kermit      | Frog           |
| 124             | Gonzo      |Great           |
| 125             | Cookie     |mosnter      |
------------------------------------------------------


See my previous post that is relevant for your information particularly ID: 37817645 that is relevant to this question as above.



<?php

	// 1 create a database connection
  	$conn = mysql_connect('localhost', 'root', 'root') or die ('Error connecting to mysql');
	//$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
	
	// 2 select a database to use
 	$databaseName = "collegeData"; 
 	$tableName = "studentTable";	
 	$conn = mysql_select_db($databaseName) or die( "Unable to select database");	


	
	$emails = array();
	$query = "SELECT *, CONCAT('studentID', '@mydot.com') AS 'Email' FROM 'studentID'  LIMIT 10";
	$result = mysql_query($query,$conn_to_database);

	while($row = mysql_fetch_object($result)):
   	 $emails[] = $row->Email;
	endwhile;

	//mysql_free_result($result);
	mysql_close($conn);

?>

Open in new window

0
 

Author Closing Comment

by:Redscrapbook
Comment Utility
Thank you everyone who has contributed to the question.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now