As it exists now, I have some PHP code set up so a customer can "login" with his/her customer number (job number). But I want to give them the option to use either their number or their email address. I understand the code for 1 option (job number), but am confused about how to offer another option (email).

Here's how my code looks:

if(isset($_POST['submit'])) {
	$jobnumber=$_POST['jobnumber'];

	$con = mysql_connect("//","//","//");
	if (!$con)
	  {
	  die('Could not connect: ' . mysql_error());
	  }

	mysql_select_db("//", $con);

	$query = "SELECT * FROM customers WHERE job_number='$jobnumber'";
	$result = mysql_query($query);
	
	echo "<table class='sample'>";
	while ($row = mysql_fetch_array($result))  {

Thanks in advance.

You could do this, make a new field on the form that is submitting to this page.

$email=$_POST['email'];

$query = "SELECT * FROM customers WHERE job_number='$jobnumber' OR email='$email'";

OR
Use the same field on that page, but let them know that they can enter either one in that field.

$query = "SELECT * FROM customers WHERE job_number='$jobnumber' OR email='$jobnumber'";

Hi,

I gave it a shot but it didn't seem to pull the records using the email address.

<?php


if(isset($_POST['submit'])) {
	$jobnumber=$_POST['jobnumber'];

	$con = mysql_connect("localhost","root","//");
	if (!$con)
	  {
	  die('Could not connect: ' . mysql_error());
	  }

	mysql_select_db("//", $con);

	$query = "SELECT * FROM customers WHERE job_number='$jobnumber' OR email='$jobnumber'";

I would prefer to use the same field, letting the customer know to use either his/her job number or email address. Would this be the proper code?

Thanks again.

Make sure you are using the right database field name. Is it named 'email' in your database?

Here's another method. Check to be sure that the query is working in the database first... that you get results when using an email address and the SQL statement.

if (preg_match("/@/i", $jobnumber))
$query = "SELECT * FROM customers WHERE email='$jobnumber'";
else
$query = "SELECT * FROM customers WHERE job_number='$jobnumber'";

It seems I'm simply having difficulty getting results with an email address. I changed the code around to look like this:

if(isset($_POST['submit'])) {
	$email=$_POST['email'];

	$con = mysql_connect("localhost","root","//");
	if (!$con)
	  {
	  die('Could not connect: ' . mysql_error());
	  }

	mysql_select_db("//", $con);

	$query = "SELECT * FROM customers WHERE email='$email'";
	
	$result = mysql_query($query);

And it won't pull the results. If I use the jobnumber, in place of the email, it pulls fine. So I think your first method may work, but I don't know why it won't use the email to pull any data?

This question has already been answered. Start a new discussion instead.