Null pointer 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
Clamato
Forum Newbie
Posts: 1
Joined: Thu Jun 17, 2004 6:15 am

Null pointer error?

Post by Clamato »

So I've created a HTML form made up of radio buttons, that posts the various values to a PHP page.

I also have an Access database, and in it a table filled with information about job 'groups'.

The idea is, the user checks whether or not they agree with a set of statements. Their answers are saved to the database in a different table (That bit works!).

Ideally, what then happens, is it goes through and either ADDS the score, or SUBTRACTS the score, given to THAT question for THAT 'job' group.

So, in the database, I have a record called army, and then for the first question it scores 1.

I also have a record called Business and for the first question it scores 4.

If the user put "Agree strongly", or "Agree somewhat" for that question,

$army

would have 1 added to it, and

$business

would have 4 added to it.

If they had answered, disagree or disagree strongly, those numbers would have been taken away instead.

But I'm getting the following error:
Warning: SQL error: [Microsoft][ODBC Microsoft Access Driver]Invalid use of null pointer , SQL state S1009 in SQLExecDirect in c:\phpdev\www\action2.php on line 134
so heres my code:

Code: Select all

<?php 

//connection variables
$dsn = odbcgroupproj;
$user = "";
$password = "";

//connect to database
$conn =  odbc_connect($dsn,$user,$password);

//if theres no connection give an error message
if($conn <= 0){
echo "Oh Dear, Everything seems to have broken. :(";
exit;
}

//if it connects let the user know
 echo "Connected to Database Server! <br/> ";	


//Put all the answers in an array
$answer[0] = $_POST['Gender'];		
$answer[1] = $_POST['Criminal'];
$answer[2] = $_POST['License'];
$answer[3] = $_POST['Edlvl'];				
$answer[4] = $_POST['Q1'];
$answer[5] = $_POST['Q2'];
$answer[6] = $_POST['Q3'];
//...and so on up to...
$answer[48] = $_POST['Q45'];	 

//Create a query that puts the answers into the database
$sqlInsert = "INSERT INTO tblQuestionnaire (0, 1, ...all the things to be inserted... 48) VALUES ('$answer[0]', '$answer[1]', ...All the required values... '$answer[48]')";

//run the query
odbc_exec($conn, $sqlInsert);

echo "Just done the query <br/> ";

//Loop to go through the database
$data[4] = ("SELECT [4] FROM tblGroups WHERE groupCode=$groupIndex");
$data[5] = ("SELECT [5] FROM tblGroups WHERE groupCode=$groupIndex");
//...all the way up to...
$data[48] = ("SELECT [48] FROM tblGroups WHERE groupCode=$groupIndex");

echo "Just defined the second query <br/> ";

for($groupIndex=1; $groupIndex < 28; $groupIndex++){

echo "Gone into the first for loop (groupIndex) <br/> ";

	for($index = 4; $index < 49; $index++){
	odbc_exec($conn, $data['$index']);
		echo "gone into the second for loop (question index) <br/> ";
		if(($answer[$index] == 1)||($answer[$index]== 2)){
			echo "Answer is 1 or 2 <br/> ";
				Switch($groupIndex){
				case 1: $Army += odbc_result($data, $index);
					echo "Added to Army OK <br/> ";
					echo "Army is currently $Army <br/>";
				break;
			 	case 2: $Architechture += odbc_exec($conn, $data[$index]);
				break;
				case 3: $Business += odbc_exec($conn, $data[$index]);
				break;
				case 4: $Farming += odbc_exec($conn, $data[$index]);
				break;
			
//ETC...
				}
		}

		if(($answer[$index] == -1)||($answer[$index]== -2)){
			echo "Answer is -1 or -2 <br/> ";
				Switch($groupIndex){
				case 1: $Army -= odbc_result($data, $index);
				//odbc_exec($conn, $data[$index]);
				echo "took away from army ok <br/> ";
				echo "Army is currently $Army <br/>";
				break;
			 	case 2: $Architechture -= odbc_exec($conn, $data[$index]);
				break;
				case 3: $Business -= odbc_exec($conn, $data[$index]);
				break;
				case 4: $Farming -= odbc_exec($conn, $data[$index]);

				break;

//ETC....

				}
				echo "left the switch cases ok <br/> ";
			}
			echo "left the second if statement ok <br/> ";
		}
	echo "left the second for loop ok. <br/> ";
}
echo "left the first for loop ok. <br/> ";

echo "Ended! <br/> ";

?>
Very sorry about the longevity of my post, but Im not especially PHP savvy, so I dont really know where the problem really lies. Many thanks in advance if you can help me out at all! :cry:
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

where line 134 is?
Post Reply