PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Mon Oct 22, 2018 8:25 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Fri May 22, 2015 12:08 am 
Offline
Forum Newbie

Joined: Thu May 21, 2015 10:21 pm
Posts: 1
Hello.

My name is Victor Rivarola. I am currently working on a system that is currently eating the first row. Yes, I have made sure that I am not fetching the rows at an incorrect time.

But first, I know that the mysql_* functions have been depreciated and should not be added to new code. Well, this is not new code but existing code I am maintaining.

This is my code:

Syntax: [ Download ] [ Hide ]
<?php
include_once("config.php");

ob_start('mb_output_handler');
mb_internal_encoding('UTF-8');
mb_http_output('UTF-8');
mb_http_input('UTF-8');
mb_language('uni');
mb_regex_encoding('UTF-8');
header("Content-type: text/html; charset=utf-8");

// These combined checks both verify the validity of the input
// and prevent against SQL injection
$city = @$_GET['city'] or die("Required parameter(s) is missing.");
is_numeric($city) ? true : die("Improper city code received.");

$sql  = "
SELECT schools_ID
,name
FROM InfResp_schools
WHERE cities_ID=$city
ORDER BY name ASC
"
;

$result = mysql_query($sql) or die(mysql_error());

while ($row = mysql_fetch_assoc($result)) {
        echo "<options value=\"".$row["schools_ID"]."\">".$row["name"]."<option>\n";
}

mysql_free_result($result);
DB_disconnect();

?>
 


The InfResp_schools table has 3 fields in it, schools_ID which is the primary key, cities_ID which is a foreign key to a different cities table, and the name field whose contents should be obvious.

This is fed using AJAX and jquery right into a select box. This part is working perfectly.

I have searched for this problem's solution for a long time. While I have found similar problems, it is always caused by people inserting a superfluous mysql_fetch_assoc(). As you can see, I am not doing that.

I have checked the above SQL command for various city codes in my database. The result is perfect. So I know that my SQL is fine. It must be a problem in my PHP.

Anyway, the result is always the same. The first school gets omitted for all cities in my database. Does anyone has an idea why?


Top
 Profile  
 
PostPosted: Fri May 22, 2015 10:53 am 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13581
Location: New York, NY, US
If you comment out the lines at the top for output buffering and headers, what does it output then?

_________________
(#10850)


Top
 Profile  
 
PostPosted: Fri May 22, 2015 11:40 am 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6617
Location: WA, USA
Invalid HTML:
Code:
<options

And the "closing" tag is missing the slash.


Top
 Profile  
 
PostPosted: Fri May 22, 2015 3:13 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13581
Location: New York, NY, US
:roll:

_________________
(#10850)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group