SunQuest
           Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old May 23rd, 2003, 08:06 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
Newbie PHP/MySQL problem

Hi, I'm learning how to run PHP/MySQL from tutorials on this site. They're really great. I was using one of the given examples, which I'd modified for my database. The problem is that when I access the PHP file, it doesn't return a darn thing. Just a white page. What did I screw up?

php Code:
Original - php Code
  1. <?php
  2. $db = mysql_connect(xxxxxxxxxx);
  3. mysql_select_db("Honor_Bios",$db);
  4.  
  5. $first_name=$_GET[first_name];
  6. $last_name=$_GET[last_name];
  7. $hometown=$_GET[hometown];
  8. $age=$_GET[age];
  9. $major=$_GET[major];
  10. $anything=$_GET[anything];
  11. $id=$_GET[id];
  12.  
  13. $result = mysql_query("SELECT * FROM Freshmen",$db);
  14. echo "<TABLE BORDER=2>";
  15. echo "<TR><TD><B>Full Name</B><TD><B>Nick Name</B><TD><B>Options</B></TR>";
  16. while($myrow = mysql_fetch_array($result))
  17. {
  18. echo "<TR><TD>".$myrow["first_name"]." ".$myrow["last_name"]."<TD>".$myrow["major"];
  19. echo "<TD><a href=
  20. Warning: Unexpected character in input: '' (ASCII=92) state=1 in /www/codewalkers.com/www/tutorials.php on line 164
  21. "view.php?id=".$myrow[id]."">View</a>";
  22. }
  23. echo "</TABLE>";
  24. ?>

Reply With Quote
  #2  
Old May 27th, 2003, 11:25 AM
Jester Jester is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: England
Posts: 271 Jester User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Newbie PHP/MySQL problem

Are you sure that the mysql connection and db select is working?

Try changing second line to something like:

php Code:
Original - php Code
  1.  
  2.  
  3. if ($db) {
  4.   mysql_select_db($mysqldbname) or die("Could not select     database");
  5.  
  6. } else {
  7.   echo "
  8.     <html>
  9.     <head>
  10.     <title>No Connection Available</title>
  11.     </head>
  12.     <body>
  13.     <p>A connection to the database server is not possible at the current time.
  14.     Please try again later.</p>
  15.     </body>
  16.     </html>n
  17.     ";
  18.     exit();
  19. }
  20.  


This will tell you if the db server is not letting you in, or if the db cannot be selected.

J

Reply With Quote
  #3  
Old May 27th, 2003, 07:50 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: Newbie PHP/MySQL problem

Well, I completely cropped the rest of my php script out and put your code in. This is my code:

php Code:
Original - php Code
  1. <HTML>
  2. <BODY>
  3. <?php
  4. $db = mysql_connect("xxxxxxxxx", "xxxxxxx", "xxxxxxxxxx");
  5. if ($db) {
  6.   mysql_select_db("Honor_Bios",$db) or die("Could not select     database");
  7.  
  8. } else {
  9.   echo "
  10.     <html>
  11.     <head>
  12.     <title>No Connection Available</title>
  13.     </head>
  14.     <body>
  15.     <p>A connection to the database server is not possible at the current time.
  16.     Please try again later.</p>
  17.     </body>
  18.     </html>n
  19.     ";
  20.     exit();
  21. }
  22. ?>
  23. </BODY>
  24. </HTML>


It pulls up a blank page, too. Now I'm really confused. When I View Source both this page and my other php page that wasn't working, both show <HTML><BODY></BODY></HTML> in the source and nothing more. Despite this, other PHP and MySQL scripts are working.

ARGH!

Thanks if you can help.

Reply With Quote
  #4  
Old May 28th, 2003, 09:21 AM
Jester Jester is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: England
Posts: 271 Jester User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Newbie PHP/MySQL problem

That's a good thing!

When php parses, it's invisible at source. What you are seeing is the <HTML><BODY></BODY></HTML> tags that you have put around your php code (remember that php does not have to be located within the <BODY> tag though - you can stick php right at the top and do your html afterwards. The only time that you would see something else from the below code is if there was a problem and the echo error or die statement come into play.

As there is nothing else being displayed it means that you are connected correctly to the db server and are allowed access to the selected db. If this was working in your first code then I suggest adding a check on your $result after running the sql like:

php Code:
Original - php Code
  1.  
  2. if (!$result) {
  3. echo 'opps';
  4. exit();
  5. }


to see if your sql is executing correctly. It may be that there is a problem with your $_GETs. (might be worth doing an echo $_GET['first_name']; etc for each of your variables at the top of your php to see if they are being passed correctly)

I also notice that you are using $_GET[first_name]; instead of $_GET['first_name']; this may be the cause of all your woes!

Good luck and let me know how you get on,

J

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > Newbie PHP/MySQL problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway