473,399 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Error when using a variable to select database table

16
Hi,
I have a script that I need to use a variable to select the database table that I want to update or to get the results from. But for some reason when I use the variable I get error. If I replace the variable with the table name, it works fine.

Here is the part of the code related to this issue:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $memberID = $_GET['cm'];
  3. if ($memberID < 50001)
  4.     $data_table = 'new_members' &&
  5.     $auth_token = "first_token";
  6. else
  7.     $data_table = 'old_members' &&
  8.     $auth_token = "second_token"; 
  9.  
  10.  
  11.  
  12.     $find_customer = mysql_query("SELECT * FROM '$data_table' WHERE id = $memberID");
  13.     while($customer_info = mysql_fetch_array($find_customer))
  14.     {
  15.     $customer_full_name = $customer_info['first_name'] . " " . $customer_info['last_name'];
  16.     $customer_email_address = $customer_info['email'];
  17.     }
  18. ?>
  19.  
Sep 9 '07 #1
5 1969
pbmods
5,821 Expert 4TB
Heya, Doc.

Try using backticks instead of quotes:
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM `$data_table` WHERE id = $memberID
  2.  
Sep 9 '07 #2
doc1355
16
I did that but same problem, still not connecting to the table.
I also tried with out quotes, but no luck.
Sep 9 '07 #3
pbmods
5,821 Expert 4TB
Heya, Doc.

What happens when you echo mysql_error()?
Sep 9 '07 #4
doc1355
16
I get multiple Undefined variable error messages.


Notice: Undefined variable: customer_email_address in F:\USERS\username\www\live\forms\registration\succ ess.php on line 177

Notice: Undefined variable: customer_full_name in F:\USERS\username\www\live\forms\registration\succ ess.php on line 173
Sep 9 '07 #5
code green
1,726 Expert 1GB
Examine this a bit closer
[PHP]if ($memberID < 50001)
$data_table = 'new_members' &&
$auth_token = "first_token";
else
$data_table = 'old_members' &&
$auth_token = "second_token"; [/PHP]
Sep 10 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Wayno | last post by:
My php logs are coming up empty. I have done all I can think of, and all that made sense to me. Can someone take a look at my php.ini please and tell me what you think may be the problem. I...
0
by: Trophy Thief | last post by:
I'm getting an odd error when I try to run a select statement in my stored procedure. I need to select records where one field = the first host variable, and the second host variable is between the...
3
by: Serious_Practitioner | last post by:
Hello, all - A few days ago, I posted the following message - Hello all, and thank you for your help in the recent past. Got a new error message in the last few days. While working with...
8
by: ST | last post by:
Hello everyone, Can anyone help me with this error above when I debug my web app project in vstudio.net?? I can't figure it out! It was working fine for months, and now all of a sudden it's not!!...
0
by: RCapps | last post by:
When running the below SQL Query I keep getting the following error: Server: Msg 4924, Level 16, State 1, Line 1 ALTER TABLE DROP COLUMN failed because column 'ContractDef' does not exist in table...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
3
by: Leighya | last post by:
Im currently working on this xml file but when i load it to Mozilla, i got an error "Error Loading Stylesheet: Xpath parse failure: invalid variable name" It loads on IE properly. Only with the...
15
by: Lawrence Krubner | last post by:
Does anything about this script look expensive, in terms of resources or execution time? This script dies after processing about 20 or 25 numbers, yet it leaves no errors in the error logs. This is...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.