Results Not Being Passed?

I’m trying to create a page that communicates with my CRM to allow a custom to check the status of their account. Here’s what I’ve created so far but every time I get the last echo (which I shouldn’t), and that tellsme something isn’t being passed to the next correctly.

I know you guys are brilliant and can help me out. :wink: :wink: :wink:

[php]<?php
$hostname = “it is a secret”;
$username = “it is a secret”;
$password = “it is a secret”;
$email = $_POST[“Email”]; //comes from HTML form on previous page

//connect to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die(“Unable to connect”);
echo “Connected
”;

//select a database to work with
$selected = mysql_select_db(“it is a secret”,$dbhandle)
or die(“Could not select database”);
echo “Selected Database
”;

//match submitted email to email in database and get record id number
$setemail = mysql_query(“SELECT id FROM email_addresses WHERE email_address=’$Email’”)
or die(“Could not select Email Addresses”);
echo “Email Address Found
”;
$setemailname = mysql_fetch_assoc($setemail);

//get record id of email and relate to record id of account in database
$setuser = mysql_query(“SELECT id FROM email_addr_bean_rel WHERE bean_id=’$setemailname’”)
or die(“Could not select Email Address Bean Relate”);
echo “Related Bean Found
”;
$setusername = mysql_fetch_assoc($setuser);

//get account status of account id in database
$result = mysql_query(“SELECT status_c FROM accounts_cstm WHERE id_c=’$setusername’”)
or die(“Could not select Accounts_cstm”);
echo “Status found
”;
$status = mysql_fetch_assoc($result);

//return appropriate response
if ($status == ‘PendingMR’) {
echo “We are missing some information from you. Please call us.”;
} elseif ($status == ‘Lead’) {
echo “You have not completed your application. Please visit www.com”;
} elseif ($status == ‘Waiting’) {
echo “We have received all of your information and are processing your account request.”;
} elseif ($status == ‘CreditRev’) {
echo “It looks like we need additional information to complete the setup of your account.”;
} elseif ($status == ‘SetupPending’) {
echo “We have shipped your equipment and emails your user login info.”;
} elseif ($status == ‘SetupComplete’) {
echo “You have already received your equipment and user login info.”;
} elseif ($status == ‘Closed’) {
echo “Your account has been closed”;
} elseif ($status == ‘Declined’) {
echo “We’re sorry! We were unable to set you up.”;
} elseif ($status == ‘Incomplete’) {
echo “It looks like we need additional information to complete the setup of your account.”;
} elseif ($status == ‘Withdrawn’) {
echo “It looks like you told us to cancel your application before we could finish processing it.”;
} else {
echo “It looks like we’re having trouble finding you. Please contact us so we can get some more information.”;
}

?>
[/php]

First things first. You are using obsolete Mysql code. Us PDO or Mysqli. Additionally, your code is completely vulnertable to an SQL Injection attack.

I am sure you dont need all those query’s to get what you want. Nevertheless, On each query result, do a print_r($query_value_here); and make sure you are getting the results you expect.

I would also suggest you post your database schema. I suspect you have a bad design.

With all those status conditions, you would do well to put those in the database.

Your queries could be simplified with joins…

       SELECT  
 		email_addresses.id 		as email_id, 
 		email_addr_been_rel.id 	as email_addr_id, 
 		accounts_cstm.status_c 	as status
 	FROM email_addresses 
 	LEFT JOIN email_addresses ON(email_addr_been_rel.bean_id = email_addresses.id)
 	LEFT JOIN accounts_cstm ON (accounts_cstm.id_c = email_addr_been_rel.id)
 	WHERE email_address='$Email'

Also you should look into PDO or mysqli
http://php.net/manual/en/book.pdo.php
http://php.net/manual/en/book.mysqli.php

If you put all your statuses into a table you could then LEFT JOIN status USING (status_id) or something similar and reduce your php code significantly.

Also if your ID’s are Integers don’t wrap them in quotes. Only use ‘’ for strings ie ‘$my_string’, $my_int

Kevin,
When I put that into it, it doesn’t print any variables. So perhaps there is something wrong at the begining of my code?

[member=73602]polk_farody[/member],
I am unable to manipulate the database in any way as it was created by a third part program and I have no control over it’s design.

Also, i don’t think the join will work as you have it above since each of the variables I am calling are stored in a different table.

This is how the system is setup.

An email address is assigned by an email ID (email addresses table).
That email ID is linked to an account ID (related bean table).
That account ID will tell me the status of the account (recorded in account table).

Thoughts?

Did you put your own variable in there or just paste it exactly as I wrote it? You cant just paste it in. Use YOUR variable.

Yes - I put my variable in there.

I decided to go with a different search variable that is stored in the same table as the status and was able to get this to work.

Sponsor our Newsletter | Privacy Policy | Terms of Service