xampp and (mysql connection not working)

Discussion in 'PHP' started by bobocheez, Feb 13, 2009.

  1. #1
    Hey,
    Just started learning PHP and cant go any further.



    It seems to be working at first glance, but then does nothing.

    I'm using xampp and have everything setup.
    Whenever this script loads it shows the die comment cant connect: in the //SELECT DATABASE operation, but nothing else so I don't know what to do.

    the //TEST connection does not work either - just if anyone asks for any reason

    database: tutorial
    localhost
    user: root
    pass:

    <?php
    //OPENS CONNECTION TO MYSQL SERVER
    $dbc = mysql_connect('localhost','root','');
    if (!$dbc){
      die('Not connected:' .mysql_error());
      }
      
    //SELECT DATABASE
    $db_selected = mysql_select_db("tutorial", $dbc);
    if (!$db_selected);
    {
     die ('cant connect:' .mysql_error());
     }
    //TEST
    $query="UPDATE tutorial SET email='hope_this_works' WHERE username='bobo'";
    $result=mysql_query($query);
     
    ?>
    PHP:
     
    bobocheez, Feb 13, 2009 IP
  2. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #2
    Can you open phpmyadmin from the localhost tab?

    Are you sure mysql and Apache have been started using the bat file.

    If yes to both of the above, did you create the DB and install the tables for the script? This is what I really think your problem is.
     
    Colbyt, Feb 13, 2009 IP
  3. bobocheez

    bobocheez Active Member

    Messages:
    403
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #3
    Yes to all 3

    It just does not connect to the tutorial database
     
    bobocheez, Feb 13, 2009 IP
  4. bobocheez

    bobocheez Active Member

    Messages:
    403
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #4
    What about the Collation
    and MySQL connection collation

    What are the defaults usually?
     
    bobocheez, Feb 13, 2009 IP
  5. bobocheez

    bobocheez Active Member

    Messages:
    403
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #5
    Ok
    nevermind I got it.

    I got semi-colon happy
    the ; on the second if statement should not be there
     
    bobocheez, Feb 13, 2009 IP
  6. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #6
    You will master the use of the semi-colon if you mess with PHP much. :) It will get to the point when where the error message pops up and you say damn semicolon AGAIN.
     
    Colbyt, Feb 14, 2009 IP
  7. bobocheez

    bobocheez Active Member

    Messages:
    403
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #7
    Haha,
    So I've been told

    for anyone randomly browsing this, here is the final working code.

    //OPENS CONNECTION TO MYSQL SERVER
    $dbc = mysql_connect('localhost','root','');
    if (!$dbc){
    		die('Not connected:' . mysql_error());
    		}
    		
    //SELECT DATABASE
    $db_selected = mysql_select_db('tutorial', $dbc);
    if (!$db_selected){
    	die ('cant connect:' . mysql_error());
    	}
    
    //TEST CONNECTION
    $query="UPDATE users SET email='hope_this_works' WHERE username='bobo'";
    $result=mysql_query($query);
    if (!$result){
    	die ('connection failed ->' . mysql_error());
    	}
    PHP:
     
    bobocheez, Feb 14, 2009 IP