Forum Moderators: coopster

Message Too Old, No Replies

Query Output Problem

Problem getting query output from two tables to display

         

bmalex

8:25 pm on Mar 21, 2006 (gmt 0)

10+ Year Member



Greetings Forum,
Can anyone look at this script and tell me why the $email field is not displaying?
I am fairly new to php and I know it is propably something simple but I can not, for the life of me, find out where my mistake is. I get no errors from echo mysql_error().'<br>';

Please help!

<?php
include ("../config/config2.inc");
session_start();
if(!isset($s_email))
{
header("Location: logon.htm");
exit();
}
@$link = mysql_connect(SYSTEM,USERNAME,PASSWORD);
if(!$link)
{
echo "Database seems to be down";
exit;
}
mysql_select_db(DATABASE) or die( "Unable to select database");
$in_clause = ""; for($i=0;$i<sizeof($select_asset);$i++)
{
if($in_clause=="")
$in_clause = "in (" . $select_asset[$i];
else
$in_clause = $in_clause . "," . $select_asset[$i];
}
$in_clause = $in_clause . ")";
$query = "Select * from clientpass,clientname where clientpass.email='$email' and clientname.asset_id " . $in_clause;
$result =mysql_query($query);
echo mysql_error().'<br>';
if(!$result)
{
echo mysql_error().'<br>';
echo "Error - Could not get asset information from database.";

mysql_close();
exit;
}
$row = mysql_fetch_object($result);
echo"
<html>
<head>
<title>UniCorp Services, Inc.</title>
</head>
<body style='font-family: Arial; font-size: 12pt' text='black' link='black' bgcolor='#FFFFFF' vlink='black' alink='black'>
<table border='1' bgcolor='#C0C0C0' width='92%' height='313'>
<tr><td bgcolor='#F2F3F1' width='48%' height='16'>
<input type=text name=\"clientname\" size=\"30\" value=\"".$row->clientname."\" ><br>
<input type=text name=\"email\" size=\"30\" value=\"".$row->email."\" >
</td>
</tr>
</table>
<body></html>";
?>

jatar_k

12:00 am on Mar 22, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld bmalex,

try changing these 2 lines

$result =mysql_query($query);
echo mysql_error().'<br>';

to this

$result =mysql_query($query) or die (mysql_error());

not sure if that will make a difference or not

you could also try echo'ing $query after you build it to see if it is properly constructed

bmalex

4:40 pm on Mar 22, 2006 (gmt 0)

10+ Year Member



Thanks jatar_k

I changed the lines as you suggested. It did not change the output. It seems like the $in_clause is somehow preventing the script from displaying the $email output.
I need to figure out how to output the query for $in_clause from one table and $email from another table!
Any other suggestions?

Again, thanks

bmalex

4:41 pm on Mar 22, 2006 (gmt 0)

10+ Year Member



ps. how do you log out of webmasterworld?

jatar_k

4:56 pm on Mar 22, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



did you try echoing the query?

$query = "Select * from clientpass,clientname where clientpass.email='$email' and clientname.asset_id " . $in_clause;
echo '<p>my query is: ',$query;

the only mention I see of $email is checking whether it is set, almost like this was coded with register_globals thought to be on and maybe they aren't, which they shouldn't be

maybe before you use it in your query try
$email = $_POST['email'];

that is assuming it is posted from a previous form

--------------

to logout
click on the 'control panel' link mear the top of the page
then click on 'signout' near the bottom of the options list

bmalex

7:35 pm on Mar 22, 2006 (gmt 0)

10+ Year Member



Thanks again jatar_k,

Let me explain how $email gets into to script. Hopefully this will let you see what I need to do with it.

A client logs on to the website with their email address as the username, hence $email.
The output page from logon is this search form with $email like so....

<form method='POST' action='client_search2.php'>
<table border='1' width='80%' bgcolor='#FFFFFF'>
<tr>
<td width='100%' bgcolor='#C0C0C0' colspan='2'><p align='center'><font color='#000000'>Select A Search Criteria</td>
</tr>
<tr>
<td width='50%' bgcolor='#DDDDDD'>Loan Type&nbsp;&nbsp;</td>
<td width='50%' bgcolor='#DDDDDD'><select size='1' name='type'>
<option></option>
<option>All</option>
<option>Agriculture</option>
<option>Commercial &amp; Industrial</option>
<option>Commercial Lease</option>
<option>Commercial Real Estate</option>
<option>Consumer</option>
<option>Franchise</option>
<option>JDC</option>
<option>Residential</option>
</select></td>
</tr>
<tr>
<td width='50%' bgcolor='#C0C0C0'>You are logged in as:</td>
<td width='50%' bgcolor='#C0C0C0'><input type=text name=\"email\" size=\"30\" value=\"".$row->email."\" >
</td>
</tr>
</table></center></div>
<input type='submit' value='Search' name='B1'><input type='reset' value='Reset' name='B2'>
</form>

Now, when the client makes a selection and then submits the form, the next page pulls any matches from the db and display them like so......and here is where I lose the value $email

echo"<table border='1' width='850' cellspacing='1'>
<tr>

<td width='466' colspan='7'><input type=text name=\"email\" size=\"30\" value=\"".$row->email."\" >Your Search Results</td>
</tr>
<tr>

<td>Select</td>
<td >Asset Number</td>
<td>Asset Name</td>
<td>Current UPB</td>
<td>Lien Position</td>
<td>Location</td>
<td>Asset Type</td></tr></table>";

while($row = mysql_fetch_object($result))
{

echo"
<table border='1' width='850' cellspacing='1'>
<tr>
<td><input name='select_asset[]' type='checkbox' value='$row->asset_id'></td>
<td>$row->loan_number</td>
<td>$row->loan_name</td>
<td>$row->balance</td>
<td>$row->position</td>
<td>$row->location</td>
<td>$row->type</td></tr></table>";
++$count;
}

$found_records = "true";

if ($found_records == "false")
{
printf("%s<br>\n", "<p><br>No Assets where found which matched the search criteria.</p>");
}

You suggested $email = $_POST['email']; and I think this will pass $email on through script. If so, where do I place it in the script? If not, then can you tell how to keep $email all the way through the script?

Please forgive my longwindedness, but I am a desperate novice in the forum and in coding. But I am trying to get good at this.

Again thanks

jatar_k

8:21 pm on Mar 22, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



exactly so you are posting it

all posted variables and values exist in the $_POST superglobal array

you need to pull it out of there and then put it into your $email variable

I think I would put it in right in between these two lines

$in_clause = $in_clause . ")";
$query = "Select * from clientpass,clientname where clientpass.email='$email' and clientname.asset_id " . $in_clause;

like so

$in_clause = $in_clause . ")";
$email = $_POST['email'];
$query = "Select * from clientpass,clientname where clientpass.email='$email' and clientname.asset_id " . $in_clause;

that way it will be available to use in your query

what is this
if(!isset($s_email))

makes me think you might just be using the wrong variable. Any idea what s_email is?

bmalex

9:50 pm on Mar 22, 2006 (gmt 0)

10+ Year Member



jatar_k

if(!isset($s_email)) comes from the session variable in my config2.inc file.

<?php
include ("../config/config2.inc");
// start session and bring in session variables
session_start();

now the $email becomes $s_email when the logon page is submitted...

So I must be using the wrong variable. Should it be
$s_email = $_POST['email']; ?

jatar_k

9:52 pm on Mar 22, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



maybe just forget about that line and just use $s_email in your query

bmalex

4:08 pm on Mar 23, 2006 (gmt 0)

10+ Year Member



To jatar_k

Well I finally got this part of the script to do what I needed it to do. I had to go the long way around by rebuilding and displaying the query for $email after the first query?!@# Bottom line......it's working!

Thanks for your suggestions and thanks to all in the forum who responded. You will hear from me again.

THERE IS NO SPOON