invalid link resource

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
nawhaley
Forum Commoner
Posts: 85
Joined: Wed May 18, 2005 11:43 am

invalid link resource

Post by nawhaley »

Hello I'm trying to pull some results from my database based off an input from a radio button. Then determine if it is the correct answer or not and I keep getting an errors.

Here is the relivant code

Code: Select all

$studentanswer= $_POST["answer"];
$qans = "Select * from tblAnswers where Answer='$studentanswer'";
            $qansresult = odbc_exec($link,$qans);
            $qanscorrect = odbc_result($qansresult,"Correct");
here is the error

Code: Select all

odbc_exec(): supplied argument is not a valid ODBC-Link resource in C:\\Web\\writequestion.php on line 88, referer: http://localhost/databasesessions.php
 odbc_result(): supplied argument is not a valid ODBC result resource in C:\\Web\\writequestion.php on line 89, referer: http://localhost/databasesessions.php
anyone have any ideas as to what would make this SQL statement invalid? I used one almost identical to it further up in my code like so.

Code: Select all

$queryanswers = "Select * from tblAnswers where QuestionCode ='$questioncode'";
and it works perfect does exactly what its suppose to do which is what makes this soooo confusing.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Code: Select all

echo $studentanswer;
Looks to me like the variable you're putting in your query is not what you're expecting it to be, or is null.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
nawhaley
Forum Commoner
Posts: 85
Joined: Wed May 18, 2005 11:43 am

Post by nawhaley »

its returning the right value I did a similar test but I had it come up in an external HTML page like so

Code: Select all

print('<A HREF = "testpost.php" TARGET = _BLANK> <EM> click here </EM> </A>');
     print("<BR>");
      $studentanswer= $_POST["answer"];
      $_SESSION["sanswer"] = $studentanswer;
thats the link to the external page along with variables.

Code: Select all

<?
session_start();
include 'writequestion.php';

print $_SESSION["sanswer"]."<BR>";
print $_SESSION["totalcorrect"]."<BR>";

?>
the actual test page

and finally results

Code: Select all

Blue
0
Blue "is" actualy the answer I selected for the first question so its pulling the variable correctly its just not translating into SQL properly.
Post Reply