geraldinecmc Posted December 13, 2007 Share Posted December 13, 2007 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 Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 13, 2007 Share Posted December 13, 2007 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 Quote Link to comment Share on other sites More sharing options...
geraldinecmc Posted December 13, 2007 Author Share Posted December 13, 2007 Thank you Rajiv! I made changes. However, it is still not returning anything to my page. Do you think I could forget something else? Or where could the error come from? Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted December 13, 2007 Share Posted December 13, 2007 $query = 'SELECT * FROM alpinismehiver'; Is your table name and DB name same ? Quote Link to comment Share on other sites More sharing options...
geraldinecmc Posted December 13, 2007 Author Share Posted December 13, 2007 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. Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted December 13, 2007 Share Posted December 13, 2007 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']; } ?> Quote Link to comment Share on other sites More sharing options...
geraldinecmc Posted December 13, 2007 Author Share Posted December 13, 2007 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? Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 13, 2007 Share Posted December 13, 2007 do you want it as an xml tree then you will have to specify a header header("Content-type: text/xml"); just above the first print statement Quote Link to comment Share on other sites More sharing options...
geraldinecmc Posted December 13, 2007 Author Share Posted December 13, 2007 Hey Rajiv, Well, I added the statement in the first line of my php, but still, the xml tree doesn't get printed out on the browser or the source code. Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 13, 2007 Share Posted December 13, 2007 what does it show in the source code can you post it if it not too big Quote Link to comment Share on other sites More sharing options...
geraldinecmc Posted December 13, 2007 Author Share Posted December 13, 2007 Well, it doesn't show anything in the source code of the page in the browser. No code at all Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 13, 2007 Share Posted December 13, 2007 must be a parse error again can you again post your full code ? Quote Link to comment Share on other sites More sharing options...
geraldinecmc Posted December 13, 2007 Author Share Posted December 13, 2007 <?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 Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 13, 2007 Share Posted December 13, 2007 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 Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted December 13, 2007 Share Posted December 13, 2007 I think your problem is this line $link = mysql_connect("localhost", "mydatabase4", "mypassword"); should be $link = mysql_connect("localhost", "root", "mypassword"); Quote Link to comment Share on other sites More sharing options...
geraldinecmc Posted December 13, 2007 Author Share Posted December 13, 2007 Sorry for bothering you... well I tried "root" instead of my username, but still doesn't work... Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 13, 2007 Share Posted December 13, 2007 what type of setup are you running are u using wamp ? or lamp ? Quote Link to comment Share on other sites More sharing options...
geraldinecmc Posted December 13, 2007 Author Share Posted December 13, 2007 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 Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 13, 2007 Share Posted December 13, 2007 the default username and password for WAMP,LAMP,MAMP is username = "root" password = "" try that and see if it works Quote Link to comment Share on other sites More sharing options...
geraldinecmc Posted December 13, 2007 Author Share Posted December 13, 2007 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. Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 13, 2007 Share Posted December 13, 2007 actually what your trying to do is pretty simple so there should not be any complications does it work properly on the server ? Quote Link to comment Share on other sites More sharing options...
geraldinecmc Posted December 13, 2007 Author Share Posted December 13, 2007 It doesn't wotk, no. Because when I type the url of my php into the browser, I get a blank page with nothing "printed out" on it and nothing "printed out" in the source code. Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 13, 2007 Share Posted December 13, 2007 its strange do you have access over your apache server logs you can check the errors over there. Quote Link to comment Share on other sites More sharing options...
geraldinecmc Posted December 13, 2007 Author Share Posted December 13, 2007 I'm still looking, will let you know when I find the clue. Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.