Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

setting up a my sql

  • 30-09-2011 12:51AM
    #1
    Registered Users, Registered Users 2 Posts: 210 ✭✭


    Hi

    I created a sql database. I give this database a name and i give it 1 user and a password, i am only messing about with it to see how to do it so it not real here is the info im using



    Im using cPanel/WHM

    The info i used is (Database name ire_test) (Users ire_pj) (password 12345)

    so my php scrip i put

    $dbhost = 'localhost'
    $dbusername = ire_test
    $dbpasswd = 12345
    $database_name = ire_pj

    but i cant get my form to work keeps saying Couldn't connect to server.


Comments

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


    You will have to give more information than that. What is the code you used for connecting.


  • Registered Users, Registered Users 2 Posts: 898 ✭✭✭OREGATO


    pjwhite99 wrote: »
    Hi

    I created a sql database. I give this database a name and i give it 1 user and a password, i am only messing about with it to see how to do it so it not real here is the info im using



    Im using cPanel/WHM

    The info i used is (Database name ire_test) (Users ire_pj) (password 12345)

    so my php scrip i put

    $dbhost = 'localhost'
    $dbusername = ire_test
    $dbpasswd = 12345
    $database_name = ire_pj

    but i cant get my form to work keeps saying Couldn't connect to server.

    Looks like you have mixed up your php script..

    $dbhost = 'localhost' -- fine
    $dbusername = ire_test -- I think, according to the info you provided should be 'ire_pj' -- note the ' as well
    $dbpasswd = 12345 -- looks fine but again, you may be missing the '
    $database_name = ire_pj -- again, looks like you've mixed this up, as you state your database name is 'ire_test' and again you're missing the '

    So to sum up, try this:

    $dbhost = 'localhost';
    $dbusername = 'ire_pj';
    $dbpasswd = '12345';
    $database_name = 'ire_test';


  • Registered Users, Registered Users 2 Posts: 210 ✭✭pjwhite99


    Thanks OREGATO

    i had it mixed up iv been at this for hours works great now thanks


  • Registered Users, Registered Users 2 Posts: 210 ✭✭pjwhite99


    im having bother again can any1 help wit this?

    now when i fiil out the form it will not send the email to the email address i put in the form, if you know what i mean its ment to send a email so people can press a link to make there account work

    here is the code for my register.php

    [PHP]
    <?

    include 'db.php';

    // Define post fields into simple variables
    $first_name = $_POST;
    $last_name = $_POST;
    $email_address = $_POST;
    $username = $_POST;
    $info = $_POST;

    /* Let's strip some slashes in case the user entered
    any escaped characters. */

    $first_name = stripslashes($first_name);
    $last_name = stripslashes($last_name);
    $email_address = stripslashes($email_address);
    $username = stripslashes($username);
    $info = stripslashes($info);


    /* Do some error checking on the form posted fields */

    if((!$first_name) || (!$last_name) || (!$email_address) || (!$username)){
    echo 'You did not submit the following required information! <br />';
    if(!$first_name){
    echo "First Name is a required field. Please enter it below.<br />";
    }
    if(!$last_name){
    echo "Last Name is a required field. Please enter it below.<br />";
    }
    if(!$email_address){
    echo "Email Address is a required field. Please enter it below.<br />";
    }
    if(!$username){
    echo "Desired Username is a required field. Please enter it below.<br />";
    }
    include 'join_form.html'; // Show the form again!
    /* End the error checking and if everything is ok, we'll move on to
    creating the user account */
    exit(); // if the error checking has failed, we'll exit the script!
    }

    /* Let's do some checking and ensure that the user's email address or username
    does not exist in the database */

    $sql_email_check = mysql_query("SELECT email_address FROM users WHERE email_address='$email_address'");
    $sql_username_check = mysql_query("SELECT username FROM users WHERE username='$username'");

    $email_check = mysql_num_rows($sql_email_check);
    $username_check = mysql_num_rows($sql_username_check);

    if(($email_check > 0) || ($username_check > 0)){
    echo "Please fix the following errors: <br />";
    if($email_check > 0){
    echo "<strong>Your email address has already been used by another member in our database. Please submit a different Email address!<br />";
    unset($email_address);
    }
    if($username_check > 0){
    echo "The username you have selected has already been used by another member in our database. Please choose a different Username!<br />";
    unset($username);
    }
    include 'join_form.html'; // Show the form again!
    exit(); // exit the script so that we do not create this account!
    }

    /* Everything has passed both error checks that we have done.
    It's time to create the account! */

    /* Random Password generator.
    http://www.phpfreaks.com/quickcode/Random_Password_Generator/56.php

    We'll generate a random password for the
    user and encrypt it, email it and then enter it into the db.
    */

    function makeRandomPassword() {
    $salt = "abchefghjkmnpqrstuvwxyz0123456789";
    srand((double)microtime()*1000000);
    $i = 0;
    while ($i <= 7) {
    $num = rand() % 33;
    $tmp = substr($salt, $num, 1);
    $pass = $pass . $tmp;
    $i++;
    }
    return $pass;
    }

    $random_password = makeRandomPassword();

    $db_password = md5($random_password);

    // Enter info into the Database.
    $info2 = htmlspecialchars($info);
    $sql = mysql_query("INSERT INTO users (first_name, last_name, email_address, username, password, info, signup_date)
    VALUES('$first_name', '$last_name', '$email_address', '$username', '$db_password', '$info2', now())") or die (mysql_error());

    if(!$sql){
    echo 'There has been an error creating your account. Please contact the webmaster.';
    } else {
    $userid = mysql_insert_id();
    // Let's mail the user!
    $subject = "Your Membership at Digital TV Donegal!";
    $message = "Dear $first_name $last_name,
    Thank you for registering at our website, http://www.digitaltvdonegal.com!

    You are two steps away from logging in and accessing our exclusive members area.

    To activate your membership, please click here: http://www.irelandwebdesign.biz/activate.php?id=$userid&code=$db_password

    Once you activate your memebership, you will be able to login with the following information:
    Username: $username
    Password: $random_password

    Thanks!
    The shane

    This is an automated response, please do not reply!";

    mail($email_address, $subject, $message, "From: MyDomain Webmaster<admin@mydomain.com>\nX-Mailer: PHP/" . phpversion());
    echo 'Your membership information has been mailed to your email address! Please check it and follow the directions!';
    }

    ?>

    [/PHP]



    and the domain is www.irelandwebdesign.biz

    what would be going wrong?


Advertisement