Connecting to database

Thread Solved

Join Date: May 2008
Posts: 60
Reputation: gangsta gama is an unknown quantity at this point 
Solved Threads: 0
gangsta gama gangsta gama is offline Offline
Junior Poster in Training

Connecting to database

 
0
  #1
Feb 18th, 2009
Hey whats up guys? I was using thenewboston tutorials on youtube and I am stuck. I was trying to connect to my database that i made.
  1. <?php
  2. //opens connection to mysql server
  3. $dbc=mysql_connect('localhost','kybo13','****');
  4. if(!$dbc)
  5. {
  6. die('Not connected: ' . mysql_error());
  7. }
  8.  
  9. //select database
  10. $db_selected=mysql_select_db("kybo13_game",$dbc);
  11. if(!$db_selsected)
  12. {
  13. die("Cant connect: " . mysql_error());
  14. }
  15.  
  16. //test
  17. $query="UPDATE game SET email='hopethisworks' WHERE username='kybo13'";
  18. $result=mysql_query($query);
  19. ?>
Thanks for your help guys.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 288
Reputation: chrishea is on a distinguished road 
Solved Threads: 36
chrishea's Avatar
chrishea chrishea is offline Offline
Posting Whiz in Training

Re: Connecting to database

 
1
  #2
Feb 18th, 2009
Start by changing the line
if(!$db_selsected) -to-
if(!$db_selected)
Last edited by peter_budo; Feb 21st, 2009 at 3:57 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 60
Reputation: gangsta gama is an unknown quantity at this point 
Solved Threads: 0
gangsta gama gangsta gama is offline Offline
Junior Poster in Training

Re: Connecting to database

 
0
  #3
Feb 19th, 2009
Ok thank you for that mistake I missed. It still doesnt work though.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 288
Reputation: chrishea is on a distinguished road 
Solved Threads: 36
chrishea's Avatar
chrishea chrishea is offline Offline
Posting Whiz in Training

Re: Connecting to database

 
0
  #4
Feb 19th, 2009
You have to be more explicit. "It still doesn't work" doesn't help much. I ran a modified version of your code as follows and it worked correctly:
  1. <?php
  2. //opens connection to mysql server
  3. $dbc=mysql_connect('localhost','root','');
  4. if(!$dbc)
  5. {
  6. die('Not connected: ' . mysql_error());
  7. }
  8.  
  9. //select database
  10. $db_selected = mysql_select_db("test",$dbc);
  11. if(!$db_selected)
  12. {
  13. die("Cant connect: " . mysql_error());
  14. }
  15.  
  16. //test
  17. $query="UPDATE test_table SET field1='hopethisworks' WHERE id='00001'";
  18. $result=mysql_query($query);
  19. ?>

You may have a problem with your DB or the names / parms you are using for it.

Chris
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 60
Reputation: gangsta gama is an unknown quantity at this point 
Solved Threads: 0
gangsta gama gangsta gama is offline Offline
Junior Poster in Training

Re: Connecting to database

 
0
  #5
Feb 19th, 2009
AWESOME!! Thank you for helping me. This now works.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 560 | Replies: 4
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC