Can't connect PHP Script to PHPmyAdmin.....Help?

Discussion in 'Databases' started by Maalik, Jun 30, 2011.

  1. #1
    I keep getting an "error querying the database" message when I attempt to connect.



    <html>
    <head>
    <title>Registration Form</title>
    </head>
    <body>
    <h2>Registration Form</h2>

    <?php
    $first_name = $_POST['firstname'];
    $last_name = $_POST['lastname'];
    $how_long = $_POST['howlong'];
    $how_many = $_POST['howmany'];
    $alien_description = $_POST['aliendescription'];
    $what_they_did = $_POST['whattheydid'];
    $fang_spotted = $_POST['fangspotted'];
    $email = $_POST['email'];
    $other = $_POST['other'];

    $dbc = mysqli_connect ('*****', '******', '******', '*******')
    or die ('Error connecting to MySQL server.');

    $query = "INSERT INTO members (id, first_name, last_name, how_long, " .
    "how_many, alien_description, what_they_did, fang_spotted, other, email) " .
    "VALUES ('$id', '$first_name', '$last_name', '$how_long', '$how_many', " .
    "'$alien_description', '$what_they_did', '$fang_spotted', '$other', '$email')";

    $result = mysqli_query($dbc, $query)
    or die('Error querying database.');

    mysqli_close ($dbc);

    echo 'Thanks for submitting the form. <br/>';
    echo ' and were gone for ' . $how_long . '<br/>';
    echo 'Number of aliens: ' . $how_many . '<br/>';
    echo 'Describe them: ' . $alien_description . '<br/>';
    echo 'The aliens did this: ' . $what_they_did . '<br/>';
    echo 'Was Fang there? ' . $fang_spotted . '<br/>';
    echo 'Your email address is ' . $email;
    ?>

    </body>
    </html>
     
    Maalik, Jun 30, 2011 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Change:

    $result = mysqli_query($dbc, $query)
    or die('Error querying database.');

    to

    $result = mysqli_query($dbc, $query)
    or die(mysqli_error($dbc));

    See what it shows
     
    jestep, Jul 1, 2011 IP