I am having the hardest time trying to figure out what I am doing wrong with this section of code. Basically, I am using the GET method to pull a variable from the URL which I then want to search the database for. This "ticket" is unique and I only want to pull the one row of info and store that into a array and then separate out the info and display that info. Here is my code:

<?php
function clean($str) {
	$str = @trim($str);
	if(get_magic_quotes_gpc()) {
		$str = stripslashes($str);
	}
	return mysql_real_escape_string($str);
}
$ticket = clean($_GET['ticket']);
echo $ticket;

$query = "SELECT * FROM notice_info WHERE notice_code= '$ticket'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);

$sessionCode= $row[1]; 
$sessionText= $row[2];  

echo "<b>$sessionCode</b><br>Phone: $sessionText<br>";

echo $sessionCode;
echo $sessionText;

mysql_close();
?>

The error I keep getting is: "Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in..." and refers to line 31 which is actually line 14 above:

$row = mysql_fetch_array($result);

I am also seeing no record being displayed at all, just the error.
What am I doing wrong? I am somewhat new at this so any help is appreciated. Thanks in advance.

whenever you see "Warning: mysql_XXX expects XXX to be resource..." typically it means that whatever query you attempted to execute failed. So replace your line 13 with the following instead to find out what is causing the error: $result = mysql_query($query) or die( mysql_error() );

I'm a complete moron. I completely forgot to put my connection string in there. Thanks for "or die" code. That helped me figure it out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.