Mysql error?!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Kaiser28
Forum Newbie
Posts: 2
Joined: Fri Mar 28, 2008 5:09 pm

Mysql error?!

Post by Kaiser28 »

I have the following

Code: Select all

 
function GetContent($strPageName){
        global $dbConnection;
        $strSqlStatement = "SELECT * FROM tblContent WHERE PageName="."'".$strPageName."'";
        echo $strSqlStatement;
        $result = mysql_query($strSqlStatement);
        if(!result){
            die("Database query failed".mysql_error());
        }
        return result;
}
 
 <?php 
        $pageName = $_GET["PageName"];
        
        if($pageName != NULL){
            $result = GetContent($pageName);
            if($result != NULL){
                while($content = mysql_fetch_array($result)){
                    echo "{$content['Content]}";
                }
            }           
        }
?>
 
It is giving me the following error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in

I know that the SQL Statement is correct since i pasted it in the phpMyAdmin and gives the results.

Anybody know what i am doing wrong?

Thanks
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Mysql error?!

Post by Christopher »

Code: Select all

        if(!result){
(#10850)
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: Mysql error?!

Post by it2051229 »

yeah.. you forgot to place a '$' sign on the 'if(!result)'... check your syntax
and modifiy your SQL statement, you're making it complicated lol.. do something like

Code: Select all

 
$strSqlStatement = "SELECT * FROM tblContent WHERE PageName= '".$strPageName."'";
 
Kaiser28
Forum Newbie
Posts: 2
Joined: Fri Mar 28, 2008 5:09 pm

Re: Mysql error?!

Post by Kaiser28 »

Arghhhhh :oops: freakin dollar sign lol!

I am new to php.. im used to C# and Dotnet stuff... couldn't find that $ missing :lol:

Is there any PHP IDE which helps debugging a little?

Thanks alot.
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: Mysql error?!

Post by it2051229 »

yeah USE nusphere (i use the trial version lol).. debugging your code while you are doing your code at the same time... i
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Re: Mysql error?!

Post by Mordred »

it2051229 wrote:yeah.. you forgot to place a '$' sign on the 'if(!result)'... check your syntax
and modifiy your SQL statement, you're making it complicated lol.. do something like

Code: Select all

 
$strSqlStatement = "SELECT * FROM tblContent WHERE PageName= '".$strPageName."'";
 
LOL

Code: Select all

$strSqlStatement = "SELECT * FROM tblContent WHERE PageName= '$strPageName'";
$strPageName needs escaping or converting to int, go read about SQL injection.
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: Mysql error?!

Post by it2051229 »

LOL :crazy: am trying to correct the SQL statement of Kaiser28?? Of course i do know how to do that statement... mr. trying to be smart
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Re: Mysql error?!

Post by Mordred »

it2051229 wrote:LOL :crazy: am trying to correct the SQL statement of Kaiser28?? Of course i do know how to do that statement... mr. trying to be smart
For you I'm Mister "mr. trying to be smart" :twisted:

(And all jokes aside, you did fail to demonstrate that you know how to write a "simpler" statement, something which you accuse the original poster of, so you have no base for that attitude)
Post Reply