0

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.

Edited by TheIdiot: n/a

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by TheIdiot
0

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() );

0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.