• GoDaddy Community
  • Websites + Marketing | Website Builders
  • Websites + Marketing | Website Builders

    Showing results for 
    Show  only  | Search instead for 
    Did you mean: 

    unclear on connecting php and mySql to a form on my website working in Dreamweaver

    trying to access my database i set up in go daddy account, (From mySQL and added tables in PHP myadmin, (i have xampp running both apache and mysql) in DW database panel adding new mySQL database, add host (i tried both localhost and my IP as Go daddy had no clue which i should use) my user and paas, and i hit the select button for database and i get the following error below.


    'your php server does not have the mySQL module loaded or you cant or you cant use the mysql(p) connect function'.


    I was told to make a connect.php (from Go daddy help link) which i did but it does not say what to do with it, and it has a couple other very short script pieces, like  

    $con = mysql_connect('HOSTNAME','USERNAME','PASSWORD');
    >mysql_select_db('DATABASENAME', $con)

    but also does not say where to put this script, is the saved as another php file? is this code added to every page where database will be? it simply does not say what to do with any of this scripting. can anyone help
    thank you
    1 REPLY 1
    Helper III

    Hello, @kevink!


    There are definitely a couple of things you can try.  The easiest thing to try may or may not work, but it only takes a minute.  Try replacing the mysql_connect and mysql_select_db methods with mysqli_connect and mysqli_select_db thusly:

    $con = mysqli_connect('HOSTNAME', 'USERNAME', 'PASSWORD');
    mysql_select_db($con, 'DATABASENAME');

    Note that the parameters are reversed when using mysqli_select_db.


    The PHP mysqli extension is recommended over the mysql extension, so it's possible only the former is enabled.  If that does not work, we may need to update your enabled PHP modules.  Do you have cPanel hosting?  If so, the instructions below should work.  If not, please reply back with the type of hosting you have, and hopefully we can figure out what needs to be done.


    If you've got cPanel hosting, log in to cPanel.  Click the icon labeled "Select PHP Version" (amongst the Software group).  On the following screen, you should be presented with numerous PHP extensions which are either checked or unchecked.  Find mysql and/or mysqli, and check them.  Once done, hit the (sort of hard to see) save button beneath the options on the left hand side.


    In response to where you would need to put the script - it depends.  If you put those two lines in a file called connect.php, for example, you can call this script whenever you need to connect to the database without putting the connection details in every script.  A simple example would be having two files:



    $con = mysqli_connect('HOSTNAME', 'USERNAME', 'PASSWORD');
    mysql_select_db($con, 'DATABASENAME');


    $name = $_POST['name];
    $query = "INSERT INTO tablename (name) VALUES ('".$name."')";
    mysqli_query($con, $query);

    This is a very simplistic example, but should demonstrate how to do it.  If you choose to use mysql rather than mysqli, be sure to reverse the parameters on both the mysqli_select_db and mysqli_query functions.


    Hopefully this should point you in the right direction!