Jump to content

problem with php/mysql select statement


Recommended Posts

Hi guyz

I am in need of help with my php/mysql. It has given me headaches. It works fine in mysql but not in php. basically i want to filter result for the user who is currently logged in. Can someone plzzzzzzz have a look and tell me where im going wrong. Thanks in advance

I have a following select statement
$sql = "select users.rep_name, rep_table.rep_name, rep_table.rep_id, customer_table.* " .
"from customer_table, rep_table, users ".
" where users.rep_name=rep_table.rep_name and customer_table.rep_id=rep_table.rep_id and account_no like '".$_GET['keywords']."'";

when i enter account_no it should only filter information associated with that particular "rep_name" if matched other wise it should return nothing but it still return results.


in mysql it works:
mysql> select users.rep_name, rep_table.rep_name, rep_table.rep_id, customer_tab
le.* from customer_table, rep_table, users where users.rep_name=rep_table.rep_na
me and customer_table.rep_id=rep_table.rep_id and account_no=1564;
+---------------+---------------+--------+------------+-------------------------
-+-----------------+----------+-----------------+----------+-----------+--------
------+------------+--------+--------------+
| rep_name | rep_name | rep_id | ACCOUNT_NO | CUSTOMER_NAME
| ADDRESS1 | ADDRESS2 | ADDRESS3 | ADDRESS4 | POST_CODE | TELEPHO
NE_NO | RUN_NUMBER | REP_ID | CONTACT_NAME |
+---------------+---------------+--------+------------+-------------------------
-+-----------------+----------+-----------------+----------+-----------+--------
------+------------+--------+--------------+
| Alan Fishwick | Alan Fishwick | 3 | 1564 | Southend Bathroom Centre
| 187 London Road | NULL | Southend-On-Sea | Essex | SS1 1PW | 01702 4
33445 | 9 | 3 | Mark Daniels |
+---------------+---------------+--------+------------+-------------------------
-+-----------------+----------+-----------------+----------+-----------+--------
------+------------+--------+--------------+
1 row in set (0.00 sec)

OR

mysql> select users.rep_name, rep_table.rep_name, rep_table.rep_id, customer_tab
le.* from customer_table, rep_table, users where users.rep_name=rep_table.rep_na
me and customer_table.rep_id=rep_table.rep_id and account_no=109819;
Empty set (0.00 sec)





Link to comment
Share on other sites

I hope that person is fictional, otherwise he just had his personal details splattered all over the internet.

Try this:

[code]
$query = "SELECT users.rep_name, rep_table.rep_name, rep_table.rep_id, customer_table.* FROM customer_table, rep_table, users WHERE users.rep_name = rep_table.rep_name AND customer_table.rep_id = rep_table.rep_id AND account_no LIKE '$_GET[keywords]'";
[/code]
Link to comment
Share on other sites

$query = "select users.rep_name, rep_table.rep_name, rep_table.rep_id, customer_table.* from customer_table, rep_table, users where users.rep_name=rep_table.rep_name and customer_table.rep_id=rep_table.rep_id and account_no=1564";


cant see any reason for it not to work.
have you tried using it as above to make sure it works right using static data, and not variables.

it might be the variable giving you grief.
Link to comment
Share on other sites

Do you have an "or die" clause on the mysql_query() function call? If not do something like:
[code]<?php
$results = mysql_query($sql) or die('There was a problem in the query: ' . $sql . '<br>' . mysql_error());
?>[/code]

Does any error print after you do the above?

Ken
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.