Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jan 2014
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Problem with locating database on following php script

    <?php

    DEFINE ('DB_USER', 'maxbella_creator');
    DEFINE ('DB_PSWD', 'ghns34?');
    DEFINE ('DB_HOST', 'localhost');
    DEFINE ('DB_NAME', 'maxbella_test');
    $connect = mysql_connect(DB_HOST, DB_USER, DB_PSWD, DB_NAME) or die('Failure: ' . mysql_error() );

    //mysql_select_db(DB_NAME) or die ('Could not select database: ' . mysql_error() );

    $sql="INSERT INTO tblCustomer (First Name, Email, Message) VALUES ('$_POST[first_name]','$_POST[email]','$_POST[message]')";

    if (!mysql_query($sql,$connect));
    {
    die('Error: ' . mysql_error($connect));
    }
    mysql_close($connect);
    echo readfile ("splashpage.html");
    ?>

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    The line is commented out:
    PHP Code:
     //mysql_select_db(DB_NAME) or die ('Could not select database: ' . mysql_error() ); 
    Just remove the // from there and it'll connect. You have the die's in place so it'll throw an error otherwise.

    Also, MySQL library is nearing end of life. You should consider upgrading to PDO or MySQLi as a replacement especially if the project is new.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • Users who have thanked Fou-Lu for this post:

    collegebusiness (01-26-2014)

  • #3
    New to the CF scene
    Join Date
    Jan 2014
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Part 2 of the problem

    OK, so now it connects, selects the database (thanks a TON Fou-Lu) and yet the die function still runs; does anyone have an answer as to why this may be?


    <?php

    DEFINE ('DB_USER', 'maxbella_creator');
    DEFINE ('DB_PSWD', 'Rover1806');
    DEFINE ('DB_HOST', 'localhost');
    DEFINE ('DB_NAME', 'maxbella_test');
    $connect = mysql_connect(DB_HOST, DB_USER, DB_PSWD, DB_NAME) or die('Failure: ' . mysql_error() );

    mysql_select_db(DB_NAME) or die ('Could not select database: ' . mysql_error() );

    $sql="INSERT INTO tblCustomer (FirstName, email, message) VALUES ('$_POST[first_name]','$_POST[email]','$_POST[message]')";

    if (!mysql_query($sql,$connect));
    {
    die('Error: ' . mysql_error($connect));
    }
    mysql_close($connect);
    echo readfile ("splashpage.html");
    ?>

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    I assume you mean off of the query?
    PHP Code:
                                    V
    if (!mysql_query($sql,$connect));
    {
    die(
    'Error: ' mysql_error($connect));

    Remove that semi-colon.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #5
    New to the CF scene
    Join Date
    Jan 2014
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Smile You single-handedly saved my a2 ict project!!

    I honestly cannot thank you enough; thank-you so much.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •