Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Help with MAMP

Options
  • 05-03-2012 1:22pm
    #1
    Registered Users Posts: 1,484 ✭✭✭


    Hi,

    I'm currently doing a college assignment that involves MySQL queries. I have the assignment working on my laptop running WAMP but i installed MAMP on my Mac and it doesn't seem to be working.

    I can open localhost, navigate to my project, launch phpmyadmin, create databases etc. The problem is that my project won't work - i'm not sure if i accidentally deleted something when setting it up. I can't find php.ini for example.

    In the project i use ajax/php/mysql integration. When i input a number and press enter a few echo statements should show up but nothing happens on the MAC - it works on my other laptop. It's hard to explain but i'd appreciate some help please.


Comments

  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    How do you mean nothing happens on the MAC? - this is when you enter a number?

    It could be your PHP configuration or a browser issue.

    I'm sure PHP is working normally though if you got PHPMyAdmin up.

    What script does your Ajax call? Maybe try calling this directly in the browser and seeing if any PHP errors occur.

    Worth turning on display_errors also.

    On Linux the PHP file is usually at somewhere like:
    /etc/php5/apache2/php.ini so maybe it's similar on MAC.


  • Registered Users Posts: 1,484 ✭✭✭gnolan


    Webmonkey wrote: »
    How do you mean nothing happens on the MAC? - this is when you enter a number?

    It could be your PHP configuration or a browser issue.

    I'm sure PHP is working normally though if you got PHPMyAdmin up.

    What script does your Ajax call? Maybe try calling this directly in the browser and seeing if any PHP errors occur.

    Worth turning on display_errors also.

    On Linux the PHP file is usually at somewhere like:
    /etc/php5/apache2/php.ini so maybe it's similar on MAC.

    Thanks for the quick reply. When i say "nothing happens", i mean a few echo statements should appear with results that correspond to the number inputted. The user enters a student number and the modules that the student takes are returned to the user in text format.

    I don't believe its a browser issue. I've tried it on both Safari and Chrome on the Mac.

    After searching, there seems to two php.ini files, one in /Applications/MAMP/bin/php/php5.3.6/conf and one in /Applications/MAMP/bin/php/php5.2.17/conf. Is this normal?

    When i call the script directly in the browser, i get a blank page. Perhaps because errors aren't turned on, like you said. Is there a way to turn on errors in phpmyadmin without having to edit the text of php.ini manually.

    Thanks for your help.

    EDIT: After turning on error reporting i get the message: Access denied for user 'root'@'localhost' (using password: NO) in /Applications/MAMP/htdocs/www/Shared sites/Project/php/student_query.php on line 4.

    I can't remember how to remedy this


  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    Yep, place this on top of your PHP file:

    [php]
    error_reporting(E_ALL);
    ini_set('display_errors','On');
    [/php]

    Also maybe you'd like to test PHP as follows:
    myfile.php
    [php]
    <?php
    echo phpinfo();
    ?>
    [/php]


  • Registered Users Posts: 1,484 ✭✭✭gnolan


    Webmonkey wrote: »
    Yep, place this on top of your PHP file:

    [php]
    error_reporting(E_ALL);
    ini_set('display_errors','On');
    [/php]

    Also maybe you'd like to test PHP as follows:
    myfile.php
    [php]
    <?php
    echo phpinfo();
    ?>
    [/php]

    Thanks Webmonkey. Edited the post above, have turned on error reporting and got the above error


  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    gnolan wrote: »
    Thanks Webmonkey. Edited the post above, have turned on error reporting and got the above error
    Your MySQL database has a password now that you have not configured in your application.
    On WAMP you had no MySQL password set if it worked.


  • Advertisement
  • Registered Users Posts: 1,484 ✭✭✭gnolan


    Well i've really messed things up now!!

    I went into privileges and changed user: root, password: yes - to user:root, password: no.

    Now when i start mamp i get an alert box saying: /Applications/MAMP/Library/bin/mysqlcheck: Got error: 1045: Access denied for user 'root'@'localhost' (using password: YES) when trying to connect.

    When trying to browse to mamp homepage in a browser i get: Error: Could not connect to MySQL server!


  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    Sorry I ment you should probably change your PHP files with the new password :(

    Maybe switch back your password for mysql and change your PHP file to that one if you know it.


  • Registered Users Posts: 1,484 ✭✭✭gnolan


    Webmonkey wrote: »
    Sorry I ment you should probably change your PHP files with the new password :(

    Maybe switch back your password for mysql and change your PHP file to that one if you know it.

    I have it back working the same way as before i messed it up. I would preferably want the files working on both mamp and wamp. To connect to mysql in my php files i'm using:

    $conn = mysql_connect("localhost", "root");

    Thats working in wamp and not in mamp. I need it to work when run from any computer as it is to be corrected and the lecturer won't go to any trouble of diagnosing the problem - i imagine i'll just lose marks.

    I think i might be missing something basic here.


  • Registered Users Posts: 5,246 ✭✭✭conor.hogan.2


    Maybe $conn = mysql_connect("localhost", "root", "root");


  • Registered Users Posts: 1,484 ✭✭✭gnolan


    Maybe $conn = mysql_connect("localhost", "root", "root");

    When i do that i get:

    Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /Applications/MAMP/htdocs/www/Shared sites/Project/php/student_query.php on line 13

    This is the entire code (bear in mind this works perfectly fine with WAMP):

    [PHP]
    <?php
    $q=$_GET["q"];
    // Step 1
    $conn = mysql_connect("localhost", "root");
    // Step 2
    mysql_select_db("collegeData", $conn);
    //Step 3

    $sql="SELECT * FROM studenttable WHERE studentID = '".$q."'";
    $result = mysql_query($sql);

    // Step 4
    while ($row = mysql_fetch_array($result))
    {
    // Step 5
    echo "Hello $row[firstName] $row[lastName]<br/>";
    echo "Your two course modules are $row[moduleNo1] and $row[moduleNo2]<br/>";
    }
    // Step 6
    mysql_close($conn);
    ?>
    [/PHP]


  • Advertisement
  • Registered Users Posts: 5,246 ✭✭✭conor.hogan.2


    That seems like a separate issue and is not related to the connection.

    Echo out $q and see what it contains and same with $sql maybe.

    Better yet add in some of the error checking contained in the answer here - http://stackoverflow.com/questions/2973202/php-error-mysql-fetch-array-expects-parameter-1-to-be-resource-boolean-given


  • Registered Users Posts: 1,484 ✭✭✭gnolan


    That seems like a separate issue and is not related to the connection.

    Echo out $q and see what it contains and same with $sql maybe.

    Better yet add in some of the error checking contained in the answer here - http://stackoverflow.com/questions/2973202/php-error-mysql-fetch-array-expects-parameter-1-to-be-resource-boolean-given

    Echoing out $q prints "131", the number that was entered in the text box by the user. Echoing $sql gives: SELECT * FROM studenttable WHERE studentID = '131'. So there's obviously a problem there somewhere - maybe in the quote marks?

    EDIT: Or maybe that's what $sql should look like

    I just don't get how it works properly in WAMP.


  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    I think it's just not connecting. Try putting die statements:

    [php]
    $conn = mysql_connect("localhost", "root") or die("Error connecting: " . mysql_error());
    mysql_select_db("collegeData", $conn) or die("Error selecting DB: " . mysql_error());
    [/php]


  • Registered Users Posts: 5,246 ✭✭✭conor.hogan.2


    Yes, use the error checking above/from that stack overflow link they will tell you pretty much where the problem is.


  • Registered Users Posts: 1,484 ✭✭✭gnolan


    Webmonkey wrote: »
    I think it's just not connecting. Try putting die statements:

    [php]
    $conn = mysql_connect("localhost", "root") or die("Error connecting: " . mysql_error());
    mysql_select_db("collegeData", $conn) or die("Error selecting DB: " . mysql_error());
    [/php]

    Using that code i get:

    Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: NO) in /Applications/MAMP/htdocs/www/Shared sites/Project/php/student_query.php on line 4
    Error connecting: Access denied for user 'root'@'localhost' (using password: NO)


  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    Well it's evident that your MySQL database has a password. This is the one you changed earlier.

    Either you change your PHP script to connect with a password or you change you MySQL password.

    If you want both toe work/ WAMP and MAMP, maybe you should consider both MySQL's having the same password.


  • Registered Users Posts: 1,484 ✭✭✭gnolan


    Webmonkey wrote: »
    Well it's evident that your MySQL database has a password. This is the one you changed earlier.

    Either you change your PHP script to connect with a password or you change you MySQL password.

    If you want both toe work/ WAMP and MAMP, maybe you should consider both MySQL's having the same password.

    Here are two screenshots from phpmyadmin. Last time i went to change a password i messed things up and had to reinstall mamp. Thanks for the help.

    This is how it currently looks


  • Registered Users Posts: 1,484 ✭✭✭gnolan


    Also, these are two screen shots of the localhost privileges.

    As you can see, it says password: yes, but there is no password set inside.

    On WAMP, password is set to no.


  • Registered Users Posts: 5,246 ✭✭✭conor.hogan.2


    Yeah as I said on osx (possibly linux too) the password is "root".


  • Registered Users Posts: 1,484 ✭✭✭gnolan


    Yeah as I said on osx (possibly linux too) the password is "root".

    I know i'm really having to be walked through this, but where exactly do i put the password??

    Adding "root" as a third parameter to mysql_connect gives the error:

    Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /Applications/MAMP/htdocs/www/Shared sites/Project/php/student_query.php on line 15

    Do i set root as the password in phpmyadmin? Am i setting this password just for the collegeData database or for localhost?

    Yes, i'm very confused


  • Advertisement
  • Registered Users Posts: 5,246 ✭✭✭conor.hogan.2


    That error is unrelated to the password by the looks of it.

    The root password is root and it is already set up to be that by default you can change the password in phpmyadmin to match the username and password you use in WAMP if you want it to work on both.

    Try echo'ing out:

    [PHP]
    $result = mysql_query($sql) or die($ql."<br/><br/>".mysql_error());
    [/PHP]

    That along with the other error checking code webmonkey posted should be more than enough to point you to where the error is.


  • Registered Users Posts: 1,484 ✭✭✭gnolan



    That along with the other error checking code webmonkey posted should be more than enough to point you to where the error is.

    Thanks again - i've only been doing php and mysql for the past 6 weeks so i'm pretty crap when it comes to trouble shooting. The output after entering the student number is:

    Table 'collegeData.studenttable' doesn't exist

    Well Jesus Christ anyways! The problem was a lowercase - it should have been "studentTable".

    Thanks a lot for your help conor and Webmonkey - i wouldn't have got that on my own.


  • Registered Users Posts: 5,246 ✭✭✭conor.hogan.2


    No problem.

    I would recommend always having error reporting on (while testing only) and that error checking code around all the connection/query code so to help you when it goes wrong.

    Also casing is nearly always very important too, and easily done wrong.


Advertisement