Problem with simple code

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Problem with simple code

Postby iratus » 04. July 2011 19:30

Hello

I am very new to PHP and I am trying to make some tutorials

I made a first small one --- creating a small database and calling some fields with php

Everything worked fine

Code: Select all
<?php
$db = mysql_connect('localhost', 'root');
mysql_select_db('mapscripting101', $db);
$sql = "select label, latitude, longtitude from places";
$res = mysql_query($sql, $db);
while ($row = mysql_fetch_assoc($res)) {
print $row["label"];
}
mysql_close($db);
?>


The I tried a little more advanced example with the same database but I can no make it work.

Do you have any idea what can be the problem ???

Code: Select all
<?php
$db = mysql_connect('localhost','root');
mysql_select_db('mapscripting101', $db);
$sql = "select label, latitude, longitude from places";
$res = mysql_query($sql, $db);
$allrows = array();
while ($row = mysql_fetch_assoc($res)) {
array_push($allrows, $row);
}
mysql_close($db);
print json_encode($allrows);
?>
iratus
 
Posts: 3
Joined: 04. July 2011 19:25

Re: Problem with simple code

Postby BigWetDog » 04. July 2011 19:42

seems to be the theme today, but this isn't really the best place to ask. But if you can tell us what the error is maybe we can try and help.
User avatar
BigWetDog
 
Posts: 148
Joined: 25. February 2010 15:54

Re: Problem with simple code

Postby iratus » 04. July 2011 19:56

Ok

I am taking a error msg saying

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\Website Tools\Xampp\htdocs\my_test\map102.php on line 7
[]


Do you have any suggestion where should I ask ???

Thanks again
iratus
 
Posts: 3
Joined: 04. July 2011 19:25

Re: Problem with simple code

Postby BigWetDog » 04. July 2011 20:17

check your select statements. they are different between the two samples you posted.
User avatar
BigWetDog
 
Posts: 148
Joined: 25. February 2010 15:54

Re: Problem with simple code

Postby Altrea » 04. July 2011 21:40

iratus wrote:Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\Website Tools\Xampp\htdocs\my_test\map102.php on line 7

To be a little more clear: parameter 1 of mysql_fetch_assoc has the value "false".
And this is produced in this line:
Code: Select all
$res = mysql_query($sql, $db);

Start debugging why this result is false.
MySQL Error Messages are often helpful to find errors :D
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8286
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: Problem with simple code

Postby BigWetDog » 04. July 2011 21:55

That's why I told him to check his select statement, he's got a misspelling in the second one: longitude vs longtitude

from the mysql manual:
For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error
User avatar
BigWetDog
 
Posts: 148
Joined: 25. February 2010 15:54

Re: Problem with simple code

Postby iratus » 05. July 2011 15:28

it was a spelling mistake !

Thanks guys ! I was spending hours and hours try to find out why it doesn't work !!!

Now it works

Thanks again for your help
iratus
 
Posts: 3
Joined: 04. July 2011 19:25

Re: Problem with simple code

Postby bhe » 06. August 2011 02:50

Hi,

I am new programmer in php.. My problem is a simple code in php didn't work ..
Like this

<html>
<h1> News </h1>
<hr>

<?php

echo "News post here";

?>

<hr>
</html>

when I run this, only blank page display.. Could you help me.. :( :( :( :( :(
bhe
 
Posts: 3
Joined: 06. August 2011 02:31


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 59 guests