Re: passing variables to a sql statement
| From: | Bobby Patel | Date: | Sun, 19 Jan 2003 00:00:27 +0000 |
| Subject: | Re: passing variables to a sql statement | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-132139@lists.php.net to get a copy of this message | ||
It seems that error is from an ill-formed MySql statement. Try this,
$descripQuery = "SELECT descrip from project_descrip where rowid=$foo";
echo $descripQuery ; // put in this echo after the query.
$descripResult = mysql_query($descripQuery);
echo mysql_error(); file://put this echo after query execution
Now, run it and see on screen what query is actually executed.
"Jennifer" <jennifer@whitenoisemachine.net> wrote in message
news:003401c2bf2b$0a042d20$8101a8c0@fvcrx01...
> hi, i'm hoping someone can help me out here - im trying to pass a variable
from a string in the href tag, however my sql breaks when i put a var in the
statment.
> when i replace $foo with a number, the page works fine. can someone please
tell me what im doing wrong?
>
> here is the error i get:
>
> Warning: Supplied argument is not a valid MySQL result resource in
/home/villany2k1/www.villany2k1.com/htdocs/projects/projects_descrip.php on
line 11
>
>
>
> here is my code:
>
> <?php
> $hostName="localhost";
> $userName="xxxx";
> $password="xxxx";
> $database= "projects";
> $tableName="project_descrip";
>
> $descripQuery = "SELECT descrip from project_descrip where rowid=$foo";
> mysql_connect($hostName, $userName, $password);
> $descripResult = mysql_db_query($database,$descripQuery);
> while($row = mysql_fetch_object($descripResult)){
>
> $foo = $row->descrip;
>
> echo("<font face=verdana size=1>");
> echo("<a href='projects_descrip.php?rowid=$foobar'>" .
> "$foo</a>" . " |
");
> echo("</font>");
>
> }
>
>
> ?>
>
> thanks in advance,
> jennifer
>