MYSQL_ASSOC vs. MYSQL_NUM? i keep receiving an 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
danselstudios
Forum Newbie
Posts: 24
Joined: Sat Jun 03, 2006 10:47 am
Location: Corona, CA

MYSQL_ASSOC vs. MYSQL_NUM? i keep receiving an error

Post by danselstudios »

CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:

I get this error when i use "MYSQL_ASSOC"
when i use "MYSQL_NUM" i get my results that are expected.

heres the specific code i'm using:

Code: Select all

if( $db ){ 
	$user = trim($_POST['username']);
	$pass = trim($_POST['userpass']);
	$query = "SELECT userid, useranswer FROM authenticate_user WHERE username = '$user' AND userpass = '$pass'";
	$result = mysql_query($query);
	if( $result ){
		$row = mysql_fetch_array($result, MYSQL_NUM ); // IF I USE MYSQL_ASSOC...
		if( $row ){
			echo '<br />A complete Success!<br />';
			echo $row[0].'<br />'.$row[1];               // ...AND $row['userid'] & $row['useranswer'] I GET CGI Error
		}
		else{
			$errors2[] = 'Submitted info does not match.';
		}
	}
	else{
		$errors2[] = 'Could not retrieve information. Please try again.';
	}
	mysql_free_result($result);
}
else{
        $errors2[] = 'Could not connect to database.';
}
why doesn't it work?
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post by bdlang »

I have no clue why that wouldn't work...maybe something in your code where you reference $row['index'] rather than $row[0]. What generates that error anyway? What version of PHP are you using? Is this under Dreamweaver or something similar?

Have you tried mysql_fetch_assoc()?
danselstudios
Forum Newbie
Posts: 24
Joined: Sat Jun 03, 2006 10:47 am
Location: Corona, CA

Post by danselstudios »

you know i learned about mysql_fetch_assoc and mysql_fetch_num...I suppose this is faster, or at least it reduces the number of lines of code you use to execute the command.

anyway, i don't understand why it doesn't work either way.
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

what is the error ? Please use

Code: Select all

mysql_query($sql) or mysql_error($conn);
And post the error. That will help to solve your problem.
danselstudios
Forum Newbie
Posts: 24
Joined: Sat Jun 03, 2006 10:47 am
Location: Corona, CA

Post by danselstudios »

Alright, i found the freaking error...the form's action was to a php file that doesn't exist instead of self.

thanks everyone!!!
Post Reply