RE: [PHP] Trying to add table prefix variable to query

From: Date: Tue, 10 Sep 2002 13:16:49 +0000
Subject: RE: [PHP] Trying to add table prefix variable to query
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-115846@lists.php.net to get a copy of this message
[snip] This is my query: <?php ... include("config.php"); $open = mysql_pconnect($hostname,$user,$password); mysql_select_db("$db",$open); $result = mysql("$db","SELECT * FROM " . $table_prefix . " teams WHERE username = 'admin'"); $i = 0; $total_rows = mysql_numrows($result); ... ?> This is my config file: <?php $db = "sports"; $hostname = "localhost"; $password = "mypassword"; $user = "myuser"; $table_prefix = "ccl_"; ?> This is my table name: ccl_teams [/snip] You're query reads like this now "SELECT * FROM ccl_ teams WHERE username = 'admin' You need to concatenate the variable with the text (remove the space); "SELECT * FROM " . $table_prefix . "teams WHERE username = 'admin' Here is a useful troubleshooting method; if the query returns an error, print it out. You can generally find errors quite easily. HTH! Jay Guys have feelings too. But, like…who cares? ***************************************************** * Texas PHP Developers Conf Spring 2003 * * T Bar M Resort & Conference Center * * New Braunfels, Texas * * Contact jay.blanchard@niicommunications.com * * * * Want to present a paper or workshop? Contact now! * *****************************************************

« previous php.general (#115846) next »