Page 1 of 1

Mysql error?!

Posted: Sun Mar 30, 2008 3:42 pm
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

Re: Mysql error?!

Posted: Sun Mar 30, 2008 6:21 pm
by Christopher

Code: Select all

        if(!result){

Re: Mysql error?!

Posted: Sun Mar 30, 2008 6:39 pm
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."'";
 

Re: Mysql error?!

Posted: Mon Mar 31, 2008 4:10 am
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.

Re: Mysql error?!

Posted: Mon Mar 31, 2008 8:09 am
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

Re: Mysql error?!

Posted: Mon Mar 31, 2008 8:44 am
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.

Re: Mysql error?!

Posted: Mon Mar 31, 2008 6:17 pm
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

Re: Mysql error?!

Posted: Tue Apr 01, 2008 3:05 am
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)