www.webdeveloper.com
Results 1 to 2 of 2

Thread: Can't connect to my DB

  1. #1
    Join Date
    Mar 2006
    Posts
    21

    Can't connect to my DB

    For some reason, I'm getting the error that I can't connect to my DB. I'm sure I'm missing something obvious. Any ideas?

    <?PHP
    error_reporting(7);

    #----------
    # Validate: String

    function check_string($value, $low, $high, $mode, $optional)
    {
    if ( (strlen($value) == 0) && ($optional === true) ) {
    return true;
    } elseif ( (strlen($value) >= $low) && ($mode == 1) ) {
    return true;
    } elseif ( (strlen($value) <= $high) && ($mode == 2) ) {
    return true;
    } elseif ( (strlen($value) >= $low) && (strlen($value) <= $high) && ($mode == 3) ) {
    return true;
    } else {
    return false;
    }
    }
    #----------
    # Validate: Email

    function check_email($email, $optional)
    {
    if ( (strlen($email) == 0) && ($optional === true) ) {
    return true;
    } elseif ( eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email) ) {
    return true;
    } else {
    return false;
    }
    }

    # RegisterGlobals OFF

    $FTGFirstName = $_POST['FirstName'];
    $FTGEmailAddress = $_POST['EmailAddress'];
    $FTGSubmit = $_POST['Submit'];

    # Fields Validations

    $validationFailed = false;

    if ( (! check_string($FTGFirstName, 1, 0, 1, false))) {
    $validationFailed = true;
    }

    if ( (! check_email($FTGEmailAddress, false))) {
    $validationFailed = true;
    }

    # Redirect user to the error page

    if ($validationFailed == true) {

    header("Location: form1.html");
    exit;

    }

    # Dump field values to a MySQL table

    $DBhost = "localhost";
    $DBuser = "******";
    $DBpass = "******";
    $DBName = "ZKCemails";
    $table = "Over13";
    mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");

    @mysql_select_db("$DBName") or die("Unable to select
    database $DBName");

    $sqlquery = "INSERT INTO $table
    VALUES('$FirstName','$EmailAddress')";

    $results = mysql_query($sqlquery);

    mysql_close();

    # End of PHP script
    ?>

  2. #2
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    this is a php question, fyi.

    change your dies to:
    PHP Code:
    or die ("Unable to connect: ".mysql_error()); 
    this will tell you why you can't connect.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles