Why is this not working!

This is a discussion on "Why is this not working!" within the PHP Forum section. This forum, and the thread "Why is this not working! are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Mar 24th, 2008, 18:45
Jack Franklin's Avatar
Resources Administrator

SuperMember
Join Date: May 2007
Location: Cornwall, England
Posts: 1,268
Blog Entries: 7
Thanks: 10
Thanked 4 Times in 4 Posts
Why is this not working!

Ok, sort of related to my other thread but just a simple problem. Take this class:
PHP: Select all

class content {
var 
$selector;
var 
$table;
//START OF CONTENT CLASS
    
function connect_db($user$db) {
        
$conn mysql_connect("localhost""root""") or die(mysql_error());
        
mysql_select_db($db$conn) or die(mysql_error());
    }

    function 
get($thetable$theselector) {
    
$this->selector $theselector;
    
$this->table $thetable;
    if (
mysql_query("SELECT '$selector' FROM '$table'")) {
    echo 
'Query Fine';
    }                
}

Nothing to tricky there? In the function GET it just adds the variables to the query.

On the home page:
PHP: Select all

$all = new content;
$all->connect_db(roottest);
$all->get(contentname); 
Except it doesn't work. Obviously nothing displays, but I should get a nice message telling me it's all fine. Now, if I replace:
PHP: Select all

    if (mysql_query("SELECT '$selector' FROM '$table'")) { 

With
PHP: Select all

    if (mysql_query("SELECT '$selector' FROM content")) { 

It works. Anyone help me figure out why it wont work with a variable in there?

The error MySQL gives (added error report thingy) is:
Quote:
Originally Posted by Annoying 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 '''' at line 1
Last Blog Entry: My Latest Project - Grilling Gurus... (Jun 11th, 2008)

Last edited by Jack Franklin; Mar 24th, 2008 at 18:47.
Reply With Quote

  #2 (permalink)  
Old Mar 24th, 2008, 19:14
CloudedVision's Avatar
Nerdy Moderator
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 942
Blog Entries: 8
Thanks: 2
Thanked 21 Times in 21 Posts
Send a message via AIM to CloudedVision Send a message via MSN to CloudedVision Send a message via Skype™ to CloudedVision
Re: Why is this not working!

Try this as your SQL query:

PHP: Select all

mysql_query("SELECT `$selector` FROM `$table`"
Not sure if that would work, but give it a try.
__________________
echo "Take it easy, ".$CloudedVision;
.links { site: other-road-design; blog: only-nerds-allowed; project: resource-fish; organization: ARMIES6; }
<quote>&quot;I think it's wrong that only one company makes the game Monopoly&quot; - <name>Steven Wright</name></quote>
Last Blog Entry: More Cheat Sheets (Jul 12th, 2008)
Reply With Quote
  #3 (permalink)  
Old Mar 24th, 2008, 19:17
Jack Franklin's Avatar
Resources Administrator

SuperMember
Join Date: May 2007
Location: Cornwall, England
Posts: 1,268
Blog Entries: 7
Thanks: 10
Thanked 4 Times in 4 Posts
Re: Why is this not working!

Nope, error. Wrong table name.
Last Blog Entry: My Latest Project - Grilling Gurus... (Jun 11th, 2008)
Reply With Quote
  #4 (permalink)  
Old Mar 24th, 2008, 19:20
CloudedVision's Avatar
Nerdy Moderator
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 942
Blog Entries: 8
Thanks: 2
Thanked 21 Times in 21 Posts
Send a message via AIM to CloudedVision Send a message via MSN to CloudedVision Send a message via Skype™ to CloudedVision
Re: Why is this not working!

Hmmmm..... What's the query that the PHP is generating?
__________________
echo "Take it easy, ".$CloudedVision;
.links { site: other-road-design; blog: only-nerds-allowed; project: resource-fish; organization: ARMIES6; }
<quote>&quot;I think it's wrong that only one company makes the game Monopoly&quot; - <name>Steven Wright</name></quote>
Last Blog Entry: More Cheat Sheets (Jul 12th, 2008)
Reply With Quote
  #5 (permalink)  
Old Mar 24th, 2008, 19:23
Junior Member
Join Date: Oct 2007
Location: Sweden
Age: 29
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Why is this not working!

i think is just due to the quotes; try removing them :
'$table' -> $table
Reply With Quote
  #6 (permalink)  
Old Mar 24th, 2008, 20:00
Jack Franklin's Avatar
Resources Administrator

SuperMember
Join Date: May 2007
Location: Cornwall, England
Posts: 1,268
Blog Entries: 7
Thanks: 10
Thanked 4 Times in 4 Posts
Re: Why is this not working!

No luck.

Oh well. Don't worry, I've given up anyway, it was getting to complex for me.
Last Blog Entry: My Latest Project - Grilling Gurus... (Jun 11th, 2008)
Reply With Quote
  #7 (permalink)  
Old Mar 25th, 2008, 08:17
New Member
Join Date: Jan 2007
Location: Manchester
Age: 27
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Why is this not working!

Surely you are not naming the right variable i.e. you have $selector when you should be using $theselector or $this->selector

|This would also seem correct due to the error message as $selector isn't one of the defined variables therefore you will be passing "Select '' from '' " as a query.
Reply With Quote
  #8 (permalink)  
Old Mar 25th, 2008, 10:34
Jack Franklin's Avatar
Resources Administrator

SuperMember
Join Date: May 2007
Location: Cornwall, England
Posts: 1,268
Blog Entries: 7
Thanks: 10
Thanked 4 Times in 4 Posts
Re: Why is this not working!

implrm you are a genius! As are the others! Turned out I had a typo, so aihazm's suggestion was right. The line now looks like:
PHP: Select all

    $sql mysql_query("SELECT $this->selector FROM $this->table"); 

As I said this is my first time using OOP really so I'll be making some mistakes! Thanks all.
Last Blog Entry: My Latest Project - Grilling Gurus... (Jun 11th, 2008)
Reply With Quote
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
CSS not working in IE? Jgag Web Page Design 2 Jun 5th, 2008 11:14
PNG - IE not working Phixon Web Page Design 3 Nov 30th, 2007 13:47
php not working? gsquare567 PHP Forum 10 Apr 24th, 2007 18:52
PHP not working toolmania1 PHP Forum 1 Nov 1st, 2006 05:57


All times are GMT. The time now is 08:10.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43