473,788 Members | 2,837 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error when using a variable to select database table

16 New Member
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 1987
pbmods
5,821 Recognized Expert Expert
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 New Member
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 Recognized Expert Expert
Heya, Doc.

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


Notice: Undefined variable: customer_email_ address in F:\USERS\userna me\www\live\for ms\registration \success.php on line 177

Notice: Undefined variable: customer_full_n ame in F:\USERS\userna me\www\live\for ms\registration \success.php on line 173
Sep 9 '07 #5
code green
1,726 Recognized Expert Top Contributor
Examine this a bit closer
[PHP]if ($memberID < 50001)
$data_table = 'new_members' &&
$auth_token = "first_toke n";
else
$data_table = 'old_members' &&
$auth_token = "second_tok en"; [/PHP]
Sep 10 '07 #6

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

Similar topics

1
5039
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 double-checked the path to my error log. It is in /var/www/logs/php_error_log Thanks. :) -Wayne Stevenson
0
4921
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 values of two other columns. The problem seems to occur when I check all three conditions. When I have only two of the conditions, the procedure runs to completion and I get a resultset. Interestingly, I created a MS Access database with a...
3
1751
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 different sized tables, in datasheet view, I've gotten this message -
8
2478
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!! This is the error: biopsy.searchsubject.btnSubject_Click(Object Sender, EventArgs e) in C:\INetPub\WWWRoot\biopsy\searchsubject.aspx.vb:198 System.Web.UI.WebControls.Button.OnClick(EventArgs e)
0
4130
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 'zContractDefault'. For some reason it is only returning the first 11 chars of the column name? Any help would be greatly appreciated... This query searches a DB and determines which columns are 'Invalid' if the column name is >30 and...
2
19492
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 will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge. I would be using layman's words, or maybe, my own words as how I understand them, hoping, you will understand it the same way that...
3
6930
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 mozilla browser i get an error. Would someone help me pls. Here is the code: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html"...
15
3255
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 on a server that handles a fairly demanding site. The defaults, in php.ini, have all been cranked fairly high: scripts get 180 seconds to run, and they can have as much as 256 megs of RAM. The input for this script is coming from a textarea in...
0
2897
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 will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge. I would be using layman's words, or maybe, my own words as how I understand them, hoping, you will understand it the same way that...
0
9498
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10112
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4070
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3675
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.