943,822 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 655
  • PHP RSS
Feb 18th, 2009
0

Connecting to database

Expand Post »
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.
PHP Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
gangsta gama is offline Offline
61 posts
since May 2008
Feb 18th, 2009
1

Re: Connecting to database

Start by changing the line
if(!$db_selsected) -to-
if(!$db_selected)
Last edited by peter_budo; Feb 21st, 2009 at 4:57 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reputation Points: 210
Solved Threads: 228
Nearly a Posting Virtuoso
chrishea is offline Offline
1,389 posts
since Sep 2008
Feb 19th, 2009
0

Re: Connecting to database

Ok thank you for that mistake I missed. It still doesnt work though.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
gangsta gama is offline Offline
61 posts
since May 2008
Feb 19th, 2009
0

Re: Connecting to database

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:
PHP Syntax (Toggle Plain Text)
  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
Reputation Points: 210
Solved Threads: 228
Nearly a Posting Virtuoso
chrishea is offline Offline
1,389 posts
since Sep 2008
Feb 19th, 2009
0

Re: Connecting to database

AWESOME!! Thank you for helping me. This now works.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
gangsta gama is offline Offline
61 posts
since May 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: How do I install and setup a phpbb forums with phpmyadmin?
Next Thread in PHP Forum Timeline: About opensource ?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC