Jump to content

Recommended Posts

Hello!

 

I have a database with datas. The table I'm aiming to retrieve datas from is called "alpinismehiver" and is placed inside a database called "mydatabase4". My aim is to retrieve this datas with a php file that turns my datas into an xml file. Here is my code :

 

// <?PHP

 

$link = mysql_connect("localhost", "mydatabase4", "mypassword");

mysql_select_db("alpinismehiver");

 

$query = 'SELECT*FROM alpinismehiver';

$results = mysql_query($query);

 

echo "<?xml version=\"1.0\"?>\n";

echo "<SCROLL>\n";

 

while($line = mysql_fetch_assoc($results)) {

echo "<titre>.$line["titre"]."</titre>\n";

}

 

echo "</SCROLL>\n";

 

mysql_close($link);

 

?> //

 

And the problem is (of course!  ;)) that it is not working! When I put my php file onto my root server online, it returns a blank page and no "trace" of my xml.

 

I'm learning and therefore I might forget something. Thank you for your help!

 

Geraldine

Link to comment
https://forums.phpfreaks.com/topic/81473-problem-retrieving-datas-from-a-database/
Share on other sites

your code should be

 

<?PHP

$link = mysql_connect("localhost", "mydatabase4", "mypassword");
mysql_select_db("alpinismehiver");

$query = 'SELECT * FROM alpinismehiver';
$results = mysql_query($query);

echo "<?xml version=\"1.0\"?>\n";
echo "<SCROLL>\n";

while($line = mysql_fetch_assoc($results)) {
   echo "<titre>".$line["titre"]."</titre>\n";
}

echo "</SCROLL>\n";

mysql_close($link);

?> 

it has a parse error

Well, actually, I made a little mistake, my database name is also called "mydatabase4" , therefore the actual code is :

 

//<?PHP

 

$link = mysql_connect("localhost", "mydatabase4", "mypassword");

mysql_select_db("mydatabase4");

 

$query = 'SELECT * FROM alpinismehiver';

$results = mysql_query($query);

 

echo "<?xml version=\"1.0\"?>\n";

echo "<SCROLL>\n";

 

while($line = mysql_fetch_assoc($results)) {

  echo "<titre>".$line["titre"]."</titre>\n";

}

 

echo "</SCROLL>\n";

 

mysql_close($link);

 

?> //

 

But I don't have a clue for the fact that it is not working.

Well try this, and use code tag (#) while posting so it will preserve formatting of your code... 

 

<?php
error_reporting(E_ALL);
$link = mysql_connect("localhost", "mydatabase4", "mypassword") or die("Could not connect: " . mysql_error());;
mysql_select_db("mydatabase4");

$query = "SELECT * FROM alpinismehiver";
$results = mysql_query($query) or die("Your have an error because:<br />" . mysql_error());

while($line = mysql_fetch_array($results)) 
{
   echo $line['titre'];
}
?>

Thank you for your help!

Well, when I try your code, I get the content of database printed correctly in the browser and in the source code. So I think I manage to connect to the database fine. Do you think it's something with the xml synthax or something I forgot to do while filling in the database?

<?PHP

header("Content-type: text/xml");

$link = mysql_connect("localhost", "mydatabase4", "mypassword");
mysql_select_db("mydatabase4");

$query = 'SELECT * FROM alpinismehiver';
$results = mysql_query($query);

echo "<?xml version=\"1.0\"?>\n";
echo "<SCROLL>\n";

while($line = mysql_fetch_assoc($results)) {
   echo "<titre>".$line['titre']."</titre>\n";
}

echo "</SCROLL>\n";

mysql_close($link);

?>

 

There it is  :)

Syntax is fine.. now all you have to check is your

 

1) Hostname, username, password

2) tablename

3) fieldname

 

but since your not getting anything on the browser source its a little confusing you should atleast get the first two lines try in another browser maybe it got cached

Hey!

 

I'm not sure I understand your question. I have MAMP installed on my Mac (sorry :() But when I test the script and the database, everything is online. My database is hosted online and my php file is uploaded via ftp. Do you need other details? Thank you again

Well, the thing is for now, I didn't use MAMP and tested the php and the database online directly. Oh yes, another thing, when I tested the earlier debug code of NeoN, the results printed out on the browser was my database content, but without space between the text datas. Could that affect the xml structure? Maybe it "get lost", or maybe it comes from something I didn't do correctly in the database (I'm a complete newbie) like primary key or something.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.