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.

Recommended Answers

All 9 Replies

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?

yea, it's named email.

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?

echo the $query variable before it is fired to see exactly what the query is at runtime.

not sure how to do that

echo $query;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.