Add email prefix

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

RedscrapbookAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ahoffmannCommented:
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"]);

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
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
RedscrapbookAuthor Commented:
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?
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

RedscrapbookAuthor Commented:
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

Ray PaseurCommented:
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

RedscrapbookAuthor Commented:
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

RedscrapbookAuthor Commented:
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?
Ray PaseurCommented:
... 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.
RedscrapbookAuthor Commented:
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
---------------------------------------------
RedscrapbookAuthor Commented:
------------------------------------------------------
|  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.
leakim971PluritechnicianCommented:
$query = "SELECT *, CONCAT('peopleID', '@dot.com') AS 'Email' FROM 'people' LIMIT 10";
RedscrapbookAuthor Commented:
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

RedscrapbookAuthor Commented:
Thank you everyone who has contributed to the question.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.