Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Problem with code

Posted on 2014-03-28
8
212 Views
Last Modified: 2014-03-31
I keep getting an error on the last line of this code.  I'm sure it's something stupid that I can't see.

The error is:

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /home/langsyst/public_html/Walk_Map_Display.php on line 79

Line 79 is the last line in this code.

// ****************************************************
// * Get north and south from mapfile record.         *
// ****************************************************

$SqlString1 = "SELECT * FROM mapfile WHERE 
					`SEQ` LIKE \"$work\"
				and 
					`BNMB` = \"$address\"";	

$mapfile = mysql_query($SqlString1,$conn);
$ROW = Mysql_fetch_assoc($mapfile, MYSQL_BOTH);
$north = $ROW['NOR'];
$south = $ROW['SOU'];
$_SESSION['SOUTH'] = $north;
$_SESSION['NORTH'] = ($north - 1);

			
// ****************************************************
// * Get new address from north and south             *
// ****************************************************
$SqlString2 = "SELECT * FROM mapfile WHERE 
					`NOR= \"$north\"
				and 
					`SOU` = \"$south\"";
					echo "Str2 = ";
					echo $SqlString2;	
$mapfile2 = mysql_query($SqlString2,$conn);		
$ROW1 = Mysql_fetch_assoc($mapfile2, MYSQL_BOTH);

Open in new window


Thanks
Glenn
0
Comment
Question by:breeze351
  • 4
  • 3
8 Comments
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 39962488
The usual cause of this error is a failure in the query.  MySQL_Query() has return values and the script must test these to know if the function worked or failed.  Relying on the function to work without testing the return value is AntiPractice #24.

Examples showing how to test the return values from SQL functions are shown in this article.  Scan for Run the CREATE TABLE Query and Handle Errors/Exceptions and look for the way the sample scripts handle the return value from the query functions.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39962507
A couple of errors.  Missing a 'backtik' after `NOR and I believe that data in MySQL statements is normally enclosed in single quotes.  Try this.
$SqlString2 = "SELECT * FROM mapfile WHERE 
	`NOR` =  '$north' AND `SOU` =  '$south'";

Open in new window

0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 39962527
Dave: The missing backtick is a sure problem, and when Glenn adds the error visualization code after the query, that will jump out in a way that gives immediate feedback.  I think the embedded quotes can be either kind, so long as they are escaped, if necessary.  And the backticks are probably not needed at all, unless you've named a column using blanks or SQL reserved words.  NOR and SOU are not reserved words.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 39962660
You're right about the quotes for strings.  https://dev.mysql.com/doc/refman/5.5/en/string-literals.html   I tend to prefer the single quotes in SQL statements in PHP because it makes it easier for me to read by avoiding all the \" escapes.
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 39962748
Yep, me too.  Just makes for fewer typographical errors, and anyone who knows me knows that I am the acknowledged King of Typos.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39962826
Glenn, the reason that line is an error is because query on the line before failed.
0
 

Author Comment

by:breeze351
ID: 39967231
I figured it out.  It was the single quotes
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 39967477
You won't have to "figure it out" if you write the code following the standard best practices -- PHP will tell you!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Output in PHP throwing alignment of data off issue 12 42
Wordpress Security 29 48
Inserting data into database 10 34
PHP alternative to file_get_contents('php://input') 4 58
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question