Current location: Hot Scripts Forums » Programming Languages » PHP » MySQL Syntax error when using a variable for table name


MySQL Syntax error when using a variable for table name

Reply
  #1 (permalink)  
Old 08-03-05, 09:21 PM
lppa2004 lppa2004 is offline
Newbie Coder
 
Join Date: Oct 2004
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
MySQL Syntax error when using a variable for table name

Okay why am i getting this error....

Code:
Quotations List Retrieval MySQL Error. You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ''2005_points' WHERE name LIKE '%Jonathan Selinsky%'' at line 1
Player Name	Date	Time	Rank	Bonus	Total Points
And here is the PHP code
--------------------------------------
PHP Code:

case "view_stats":


                
$year date("Y");
                
$table "$year".'_'.'points';

                echo 
"<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\">";
                echo 
"<tr>";
                echo 
"<th width=\"200\" align=\"left\"><font face=\"Arial, Helvetica, sans-serif\" size=\"2\">Player Name</font></th>";
                echo 
"<th width=\"100\" align=\"center\"><font face=\"Arial, Helvetica, sans-serif\" size=\"2\">Date</font></th>";
                echo 
"<th width=\"50\" align=\"center\"><font face=\"Arial, Helvetica, sans-serif\" size=\"2\">Time</font></th>";
                echo 
"<th width=\"50\" align=\"center\"><font face=\"Arial, Helvetica, sans-serif\" size=\"2\">Rank</font></th>";
                echo 
"<th width=\"50\" align=\"center\"><font face=\"Arial, Helvetica, sans-serif\" size=\"2\">Bonus</font></th>";
                echo 
"<th width=\"75\" align=\"center\"><font face=\"Arial, Helvetica, sans-serif\" size=\"2\">Total Points</font></th>";
                echo 
"</tr>";

                
$pname $_GET['name'];

                
$result mysql_query("SELECT * FROM '$table' WHERE name LIKE '%$pname%'") or die("Quotations List Retrieval MySQL Error. " mysql_error());

                        while (
$row mysql_fetch_array($resultMYSQL_BOTH)) {
                                
//$short = substr($row[1], 0, 100);
                                
$name $row["name"];
                                
$tdate $row["date"];
                                
$place $row["place"];
                                
$venue $row["venue"];
                                
$ttime $row["time"];
                                
$total $row["total"];
                                
$rank $row["rank"];
                                
$bonus $row["bonus"];

                            echo 
"<tr>";
                            echo 
"<td width=\"200\"><font face=\"Arial, Helvetica, sans-serif\" size=\"2\">$name</font></td>";
                            echo 
"<td width=\"100\" align=\"center\"><font face=\"Arial, Helvetica, sans-serif\" size=\"2\">$tdate</font></td>";
                            echo 
"<td width=\"50\" align=\"center\"><font face=\"Arial, Helvetica, sans-serif\" size=\"2\">$ttime</font></td>";
                            echo 
"<td width=\"50\" align=\"center\"><font face=\"Arial, Helvetica, sans-serif\" size=\"2\">$place</font></td>";
                            echo 
"<td width=\"50\" align=\"center\"><font face=\"Arial, Helvetica, sans-serif\" size=\"2\">$bonus</font></td>";
                            echo 
"<td width=\"75\" align=\"center\"><font face=\"Arial, Helvetica, sans-serif\" size=\"2\">$total</font></td>";
                            echo 
"</tr>";
                        }

                echo
"</table>";

        break; 
You can see the script in action here -
=====================================
http://lafayettepoker.com/tournament_night/index3.php
------------------------------------------------
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 08-03-05, 11:36 PM
santana santana is offline
Newbie Coder
 
Join Date: Jul 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
use $table instead of '$table'
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 08-04-05, 01:01 AM
lppa2004 lppa2004 is offline
Newbie Coder
 
Join Date: Oct 2004
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
okay i tried that earlier and i just tried it again
and i get this msg... yet i know teh database exists

Quotations List Retrieval MySQL Error. No Database Selected
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 08-04-05, 01:06 AM
lppa2004 lppa2004 is offline
Newbie Coder
 
Join Date: Oct 2004
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
as a matter of fact i just tried using the database name itself instead of the variable and get the same error
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 08-04-05, 01:24 AM
lppa2004 lppa2004 is offline
Newbie Coder
 
Join Date: Oct 2004
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
lol.. i forget to uncomment my sql connection include function
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 03:22 AM
php MySQL and variable formats - questions. irfaan PHP 0 07-18-05 01:35 AM
MySQL syntax error HairySpider PHP 2 07-12-05 07:43 AM
mysql generated variable insertion problem wwanthony PHP 6 01-10-05 09:41 PM
PHP MySQL Variable Help tgarske PHP 8 08-25-03 10:01 PM


All times are GMT -5. The time now is 10:27 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.